Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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 6x4, without causing the image to stretch or get squashed.

share|improve this question

migrated from stackoverflow.com Apr 25 '11 at 16:03

This question came from our site for professional and enthusiast programmers.

@karlphillip not sure I see why... – xenoterracide Apr 26 '11 at 12:52
In the future, please don't crosspost (SU version). If you want a post moved to another site, you can flag it and ask a mod on that site to move it – Michael Mrozek Apr 26 '11 at 21:34
up vote 7 down vote accepted

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 ...


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

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.

share|improve this answer
1024:768 is 4:3 – user unknown Apr 25 '11 at 20:14
He want's his images to be in 6:4 – Musaul Apr 25 '11 at 20:38
Yes, they should be 6:4 for printing purposes. As the printer I will be using gives best results if the images are 6:4. Any other aspect ratio, it the prints will end up showing blank white borders top/bottom, or left/right. – oshirowanen Apr 26 '11 at 10:13
@Musaul, if I use that command and replace <input_image> and <output_image> with *, will that resize and crop all images in the given directory? – oshirowanen Apr 26 '11 at 10:15
I've updated my answer to include a little script to rename all images in the same directory. On a sidenote though, 1024x683 is a very low resolution for printing photos. – Musaul Apr 26 '11 at 12:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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