Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
If you want to change the aspect ratio of an image, you can either stretch/squash it, letterbox it, or crop it. Which are you looking for? –  cjm Apr 26 '11 at 8:13
    
I would like to crop it. –  oshirowanen Apr 26 '11 at 10:11
    
Cross-posted at Unix Stack Exchange. (Don't do that!) –  Gilles Apr 27 '11 at 19:58

3 Answers 3

up vote 3 down vote accepted

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.

share|improve this answer

I guess you are using Imagemagick.The problem is not related to any software, simply you will need to do a resize keeping each photo ratio, then a crop using the other ratio(you need to loose part of the image, then, and in other cases, add a chunk at the bottom of solid black, etc). I tend to do this with certain freeware, Irfanview. Using Batch option (just open one image in the folder with irfanview, and hit b key) , I'd set advanced options as checked, then use the options there to resize and crop, it offers quite flexibility.

Nothing you couldn't do with Imagemagick, though, Surely you are letting it stretch, but you could possibly force the crop without changing the ratio...

Other way is using Photoshop automate menu, combining with an Action(macro) previously done by you.

share|improve this answer

Original image: 798x591

Target image:

$ convert /var/tmp/eid0.png -crop 798x450-10+50 /var/tmp/eid.png

798 = width  (keep original)
450 = height (customize original to total height)

-10 = x horizontally
+50 = y vertically

it works nicely.

share|improve this answer

Your Answer

 
discard

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.