What is wrong with this attempt to crop an image with ImageMagick's convert utility?

1

I am trying to make a tool that will, in imitation of responsive design on the web, make iPhone / iPad wallpapers by taking the largest centered crop-to-device-dimensions it can, and programmatically be available.

I have an original image in landscape, and commands, one per output wallpaper, like:

convert background.png -resize 320x480 -crop 320x480+0+0 background-320x480.png

However, after the conversion, background-320x480.png's dimensions are 320x239, and all of the generated images have the same aspect ratio, notwithstanding that they are intended to cover portrait and landscape resolutions across iPhones and iPads.

The same dimensions appear if I replace the first 480 with a number in the thousands.

What is appropriate use of ImageMagick's convert to shrink a master wallpaper down to the minimum dimensions that will enclose a wallpaper dimension (preserving aspect ratio), and then crop the center of the shrunken master to wallpaper dimensions and preferably center it? Let's say my original is 1600x1200 and I am trying to make a 320x480 wallpaper.

Thanks,

Christos Hayward

Posted 2013-09-12T20:32:06.777

Reputation: 753

If your original is 1600x1200 (aspect ratio 1.33), how do you expect it to resize it to 320x480 (aspect ratio 0.67)? – Peon – 2013-09-12T20:38:02.013

I intend to shrink it to 480 pixels in height, and then crop to a 320 pixel wide rectangle in the center, as stated in the question. – Christos Hayward – 2013-09-12T20:39:21.450

my comment was for your original convert command which tells convert to resize to 320x480. – Peon – 2013-09-12T20:58:18.590

"shrink... down to minimum dimensions... preserving aspect ratio... and then crop..." specifies two steps, not one. – Christos Hayward – 2013-09-12T21:59:13.197

Answers

1

  • 1600x1200 ==(40%)==> 640x480
  • crop from the center so the top left corner is moved from (0,0) to (160,0).

Try convert original.png -resize 40% -crop 320x480+160+0 reduced.png.

Peon

Posted 2013-09-12T20:32:06.777

Reputation: 771