Get information and rotate and resize with it

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
ohuebler
Posts: 2
Joined: 2016-03-26T22:44:07-07:00
Authentication code: 1151

Get information and rotate and resize with it

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Get information and rotate and resize with it

Post 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).
ohuebler
Posts: 2
Joined: 2016-03-26T22:44:07-07:00
Authentication code: 1151

Re: Get information and rotate and resize with it

Post 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
Post Reply