Page 1 of 1

Get information and rotate and resize with it

Posted: 2016-03-26T22:49:15-07:00
by ohuebler
Hello,

A couple of photos on my disk were somehow destroyed in aspect ratio. It seems that the image turned in the same aspect ratio.

I now want to fix it with the following script (bash MAC).

Code: Select all

for file in *.jpg; 
do 
read f width height < <(identify -format "%f %w %h" "$file")
convert $f -rotate 270 temp-$f 
mogrify -resize $heightx$width\! temp-$f;
done
but for some reason it only resizes to 1936x1936 instead of 1936x2592

A sample image can be found here: https://dl.dropboxusercontent.com/u/272993/IMG_0060.jpg

I tried everything for a couple of hours now but am completely clueless. Thank you for your help.

Re: Get information and rotate and resize with it

Posted: 2016-03-26T23:36:51-07:00
by fmw42
Why are you using mogrify to do what can be done in the same convert?

Code: Select all

convert $f -rotate 270 -resize ${height}x${width}\!  temp-$f
Nevertheless the "x" in your code is being taken as part of the $eightx resize arguments. So use

Code: Select all

-resize ${height}x${width}\! 
to avoid the it seeing heightx as the argument.

Or it does not want the escape

Code: Select all

-resize ${height}x${width}! 
Please always provide your IM version (along with your platform).

Re: Get information and rotate and resize with it

Posted: 2016-03-27T02:05:03-07:00
by ohuebler
Thank you so much. That did the trick:

Code: Select all

for file in *.jpg; 
do 
read f width height < <(identify -format "%f %w %h" "$file")
convert $f -rotate 270 -resize ${width}x${height}! temp-$f;
done