batch rotate horizontal pictures - command not working

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
karlrt

batch rotate horizontal pictures - command not working

Post 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
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: batch rotate horizontal pictures - command not working

Post by Drarakel »

With mogrify, you have to specify the operations first, then the filename:
mogrify -rotate "-90<" "$file"
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: batch rotate horizontal pictures - command not working

Post 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.
snibgo's IM pages: im.snibgo.com
karlrt

Re: batch rotate horizontal pictures - command not working

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: batch rotate horizontal pictures - command not working

Post 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
snibgo's IM pages: im.snibgo.com
karlrt

Re: batch rotate horizontal pictures - command not working

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: batch rotate horizontal pictures - command not working

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: batch rotate horizontal pictures - command not working

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
karlrt

Re: batch rotate horizontal pictures - command not working

Post by karlrt »

thank you for your help, because of simplicity i just rotated the pics its a wonder how much imagemagick actually can do!
Post Reply