Resizing and cropping images to an aspect ratio of 6×4 with width of 1024 pixels

command lineimage manipulationimagemagick

I have a mixed set of images, each one has a slightly different resolution with a slightly different aspect ratio from other images.

I have tried using commands like

convert -resize

and

convert -crop

but can't seem to figure out the correct command to make all images have a width of 1024 and an aspect ratio of 6×4, without causing the image to stretch or get squashed.

Best Answer

You want all your photos to be 6x4 with a width of 1024, right? That means they should be 683 pixels high.

If that is correct, what you're looking for is ...

convert <input_image> -resize 1024x683^ -gravity center -extent 1024x683 <output_image>

... where you would replace with the filename of the image you want to resize, and with the new filename.

This will crop the edges to fit the aspect and resize them to 1024x683. It will make small images larger, as well as making large images smaller to fit your size.

 

When you want to resize all images in a directory, you'll need to write a quick bash script, which would look like ...

#!/bin/bash

for f in *.[jJ][pP][gG]
do
    echo $f
    convert $f  -resize 1024x683^  -gravity center  -extent 1024x683  print_$f
done

You then just make the script executable. (Say you saved the script as rename.sh, you run chmod u+x rename.sh.) Then you run the script ./rename.sh which will resize all the images in the same directory.

Related Question