Page 1 of 1
Weird results when cropping and resizing
Posted: 2016-10-23T19:28:00-07:00
by mhulse
Hello,
I can't seem to figure out the best way to crop and resize to an exact target width and height.
My code:
Code: Select all
convert \
"001.jpg" \
-auto-orient \
-crop 3026x3072+1579+0 \
-gravity Center \
-resize 2622x2660^ \
-density 304x304 \
-quality 100 \
-depth 8 \
-units PixelsPerInch \
-strip \
+profile '*' \
+repage \
cropped-and-resized.jpg
My goal is to crop, and then resize to exactly/proportionlly fit 2622x2660 (hence the use of the carrot ^).
Unfortunately, the cropped results are unpredictable and not 2622x2660.
Also note that some of these images have orientation data straight from camera, that's why I am using auto-orient. Part of me wonders if the orientation info is creating an issue with the crop and resize?
Can anyone see where I am going wrong?
Thanks so much in advance for the help!
Re: Weird results when cropping and resizing
Posted: 2016-10-23T19:47:00-07:00
by mhulse
Ahhh, looks like I am running into issues due to the image's orientation!
The crop is based on the image's orientation before I "fix" it. This would explain why my crops are strange. When I remove -auto-orient, then my image crops great, it's just that it's rotated on it's side!
Now I need to figure out how to fix orientation before determining crop.
Re: Weird results when cropping and resizing
Posted: 2016-10-23T19:53:57-07:00
by snibgo
Try "+repage" after "-auto-orient".
Re: Weird results when cropping and resizing
Posted: 2016-10-23T20:07:16-07:00
by mhulse
snibgo wrote:Try "+repage" after "-auto-orient".
Awesome! Thank you for the tip!
Re: Weird results when cropping and resizing
Posted: 2016-10-23T22:33:38-07:00
by mhulse
So, after fixing the image's orientation using jhead, this combination of commands ended up working out for me:
Code: Select all
convert \
"uncropped.jpg" \
-auto-orient \
+repage \
-crop 3072x3115+0+9 \
-resize 2622x2660^ \
-extent 2622x2660 \
-density 304x304 \
-quality 100 \
-depth 8 \
-units PixelsPerInch \
-strip \
+profile "*" \
+repage \
"cropped.jpg"
The extent option really helped, as i noticed crop and resize were not creating an exact 2622x2660 image size (I kept getting 2633x2660).
I'm still open to hearing feedback on my command string above if you see anything out of the ordinary.
Thanks again for your help @snibgo!
Re: Weird results when cropping and resizing
Posted: 2016-10-23T22:49:56-07:00
by GeeMack
mhulse wrote:The extent option really helped, as i noticed crop and resize were not creating an exact 2622x2660 image size (I kept getting 2633x2660).
The resize with the "^" caret will fill that 2622x2660 space the best it can, even if it has to go outside the bounds in one direction or other.
Re: Weird results when cropping and resizing
Posted: 2016-10-23T22:59:20-07:00
by mhulse
GeeMack wrote:
The resize with the "^" caret will fill that 2622x2660 space the best it can, even if it has to go outside the bounds in one direction or other.
Ahh, I see! I assumed it would go outside bounds and then crop to the exact size. Thank you for clarification.
Re: Weird results when cropping and resizing
Posted: 2016-10-23T23:02:19-07:00
by snibgo
See the docs,
http://www.imagemagick.org/script/comma ... p#geometry. The caret "^" does this:
With the ^ operator, one of those dimensions will match the requested size, but the image will likely overflow the dimensions requested to preserve its aspect ratio.
Re: Weird results when cropping and resizing
Posted: 2016-10-23T23:08:51-07:00
by mhulse
snibgo wrote:See the docs,
http://www.imagemagick.org/script/comma ... p#geometry. The caret "^" does this:
With the ^ operator, one of those dimensions will match the requested size, but the image will likely overflow the dimensions requested to preserve its aspect ratio.
Awesome, thank you for the pointer. I totally overlooked that.
Re: Weird results when cropping and resizing
Posted: 2016-10-27T19:09:32-07:00
by anthony
A good summary of normal resize cropping techniques is in IM Examples
Thumbnails...
http://www.imagemagick.org/Usage/thumbnails/#fit
A final summery is in
http://www.imagemagick.org/Usage/thumbn ... it_summery
Re: Weird results when cropping and resizing
Posted: 2016-10-27T20:46:01-07:00
by mhulse
Thank you Anthony! I really appreciate the help! Reading up on that now.