Page 1 of 1

batch rotate horizontal pictures - command not working

Posted: 2010-07-08T02:00:24-07:00
by karlrt
I want to create a mosaic picture with metapixel, if i just use "metapixel-prepare" to prepare thumbnail-like pictures, all horizontally aligned pictures get to be transformed to vertical ones, but not rotated, rather crimped, i dont want to have squeezed photos in my mosaic, which gonna be printed in big.

So i thought, why not use imagemagick to rotate all pictures before, and then metapixel wont crimp any. I found
http://www.imagemagick.org/script/comma ... fl3#rotate to be useful, so i used this command:

Code: Select all

$ for file in *; do mogrify "$file" -rotate "-90<"; done
but nothing happens, it goes through every picture (i can see this in nautilus, which creates new thumbnails then) but it doesnt change anything. so i just tried

Code: Select all

$ mogrify onefile.jpg -rotate "-90<"
for horizontal file, and it seems its just not working? What to do? Is it the wrong command? does it have problems with certain jpgs? is it a bug?

Another possibility would be not to rotate the photo but to crop from every horizontally aligned picture a vertical one (so original has 600x800 px, it cuts out the upper/lower/middle part of 600x450px) Which would be the correct batch command for that (problem: only use horizontally aligned pics

Re: batch rotate horizontal pictures - command not working

Posted: 2010-07-08T02:19:22-07:00
by Drarakel
With mogrify, you have to specify the operations first, then the filename:
mogrify -rotate "-90<" "$file"

Re: batch rotate horizontal pictures - command not working

Posted: 2010-07-08T06:33:43-07:00
by snibgo
And "mogrify" will operate on a number of (wildcard) files, so you don't need the for-loop.

If you want the for-loop, "convert" would be the usual command.

Re: batch rotate horizontal pictures - command not working

Posted: 2010-07-09T00:16:22-07:00
by karlrt
hey thank you, i knew it had to do with me doing something wrong!

Do you guys know perhaps how i can realize the second option? To crop every horizontal picture?

Re: batch rotate horizontal pictures - command not working

Posted: 2010-07-09T07:35:07-07:00
by snibgo
"Crop" will do the job, eg:

Code: Select all

convert in.jpg -gravity center -crop 600x450+0+0 out.jpg
See http://www.imagemagick.org/script/comma ... ptions.php

Re: batch rotate horizontal pictures - command not working

Posted: 2010-07-09T07:59:42-07:00
by karlrt
hi snibgo, thanks for the answer, but my problem would be a bit more difficult:

a) leave all vertical images as they are
b) crop all horizontal images to a 4x3 dimension, they will have different sizes (so one might be 60x80 and needs to be cropped 60x45 (4x3), one might be 600x800 and needs to be cropped to 600x450 (4x3).

But rotate tip is already helpful!

Re: batch rotate horizontal pictures - command not working

Posted: 2010-07-09T08:19:18-07:00
by snibgo
Yes, I was just showing you how to crop with IM. You could write a script that found the current width and height and calculated the new dimensions.

Re: batch rotate horizontal pictures - command not working

Posted: 2010-07-10T17:39:31-07:00
by anthony
IM does not have a true if-then-else operation construct. Perhaps it will in the future.
As such you will probably need a wrapper script to only apply the command to horizontal pictures.

However having said that one method can do a crop with tests. Using a No-OP -distort and setting the crop size based on the -set option:distort:viewport
http://www.imagemagick.org/Usage/distor ... t_viewport

The reason you this can selectively crop is that you can use an %[fx...] expression in the -set argument. That is for each of the four 'viewport' (equivalent to a crop) arguments do a test on if the image is horizontal, and then select the appropriate argument (for example the image width, or the crop width).

On example of selective viewport distort or cropping is given in the link above, to produce a centered square cropping regardless of aspect ratio. Specifically the square will be either the width or height depending on the images aspect ratio.

Re: batch rotate horizontal pictures - command not working

Posted: 2010-07-16T12:52:59-07:00
by karlrt
thank you for your help, because of simplicity i just rotated the pics its a wonder how much imagemagick actually can do!