Resizing and cropping images to 6x4 to width of 1024
I have a mixed set of images, each one having a slightly different resolution with a slightly different aspect ratio from the other images.
I have tried using commands like:
convert -resize
and:
convert -crop
However I can't seem to figure out the correct command to make all images have a width of 1024 and an aspect ratio of 6x4, without causing the image to stretch or get squashed.
Note that 1024 is not divisible by 3, so you can't get an exact 6x4 aspect ratio. I'm approximating it to 1024x682.
The command you want is
convert in.jpg -resize '1024x682^' -gravity Center -crop 1024x682+0+0 out.jpg
-resize '1024x682^'
scales the image while preserving the aspect ratio so that either:
- width = 1024 and height >= 682, or
- height = 682 and width >= 1024
Only one of those criteria can be accomplished without changing the aspect ratio (unless the image was already 6x4).
-gravity Center -crop 1024x682+0+0
cuts a 1024x682 region centered on the center of the image. You could use a different -gravity
depending on how you want your images cropped.
You could also include a -filter
option to control the algorithm used to resize the image.