ImageMagick cropping with the incorrect dimension

72 Views Asked by At

I tried with cropping images to 5862x367. However, it crops to 367x5862. I tried the following code:

convert -crop 5862x367+0+0 +repage "/Users/ramakrishnanbalakrishnan/sites/img/test_in.JPG" "/Users/ramakrishnanbalakrishnan/sites/img/out_3.jpg"

version: ImageMagick 7.1.1-8

Original image: Download image here

after cropped image: download

1

There are 1 best solutions below

0
On

Your input image has an orientation tag of "LeftBottom". You can use "-auto-orient" to re-orient the image so the dimensions are measured from "TopLeft". This command...

magick input.JPG -auto-orient -crop 5862x367+0+0 +repage result.jpg

... will produce an image with the dimensions 2252x367. Since the input image is only 2252 pixels wide, it can't be cropped to 5862 pixels wide. If you need to add to the original dimensions you'll have to use "-extent" instead of "-crop".

Edited to add: When you're using ImageMagick version 7 you should generally use "magick" instead of "convert". Using "convert" makes IM roll back to version 6 behavior, and unless you need that for a particular reason, "magick" is the suggested command to use.