3

I'm batch processing a folder of image to a uniform width with GraphicsMagick (though I assume the same would apply to ImageMagick):

$ gm convert -resize 1000x in.jpg out.jpg

But when I inspect some of the images, I get 999px instead of 1000px.

$ gm identify -verbose out.jpg

==> Image: out.jpg
==> Format: JPEG (Joint Photographic Experts Group JFIF format
==>   Geometry: 999x591

Is there a way to enforce the right width? I assume it's doing some estimation to preserve aspect ratios.

2

Figured this out, you use an exclamation mark to enforce the elected size. From the GraphicsMagick docs:

Append an exclamation point to the geometry to force the image size to exactly the size you specify. For example, if you specify 640x480! the image width is set to 640 pixels and height to 480.

So from the example above:

$ gm convert -resize 1000x! in.jpg out.jpg

This results in an image that's exactly 1000 pixels wide:

$ gm identify -verbose out.jpg

==> Image: out.jpg
==> Format: JPEG (Joint Photographic Experts Group JFIF format
==>   Geometry: 1000x591

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.