Need help resizing

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Strahan

Need help resizing

Post by Strahan »

Hi. I have an image that's 1680x1050 that I want to convert to 1280x1024. The original image was some oddball resolution that was resized to 1680x1050 so it has pillarboxes. I am currently doing:

mogrify -resize 1280x1024 -gravity center -background black -extent 1280x1024 image.jpg

Problem is, it doesn't create it the way I want. I made examples:

Image

First is the source image. The mogrify output is the second image. What I want is the third image. Basically, it's compressing X and Y of the image to fit the desired res, whereas I want it to resize to 1024 then crop the edges. I figured OK, just calculate the ratio for 1024 (0.8) so I'd divide 1050 by 0.8 to find the same ratio horizontal spec (1312.5). I tried:

mogrify -resize 1313x1024 -gravity center -background black -extent 1313x1024 image.jpg

..but that still gave me letterboxing. What would be the proper way to go about this? Thanks!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Need help resizing

Post by snibgo »

I'm not sure of the boundaries of your source image. I assume it doesn't include the white border. It would help if you included the actual image file in your post.

In each case, you are resizing the entire image (including the black bars) so it fits within your stated dimensions, and then extending so it is exactly that size.

It seems more logical to crop off the black border, then resize to within 1280x1024, then extend to 1280x1024.
snibgo's IM pages: im.snibgo.com
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Need help resizing

Post by Drarakel »

One way to do it:
mogrify -resize x1024 -gravity center -crop 1280x1024+0+0 +repage image.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need help resizing

Post by fmw42 »

If it is just one image, I would use convert. But you can use mogrify. Either way I would suggest the following:

convert inputimage -fuzz XX% -trim -resize 1280x1024 -background black -extent 1280x1024 +repage outputimage

where XX is the fuzz factor in percent that you could use to trim if the black is not a solid color, otherwise set to 0 or remove -fuzz XX% if solid black.

This trims the black all around, resizes to 1280x1024 and if one side is smaller, then pads out to 1280x1204 with black.

As snibgo (Alan) suggested, it is usually a good idea to provide your actual image by uploading it somewhere else and posting a link here to the image.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Need help resizing

Post by anthony »

Put the +repage immediately after the -trim otherwise you may get other virtual canvas effects (probably not in this case, but you never know).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Strahan

Re: Need help resizing

Post by Strahan »

Ahh that's perfect. Thanks alot everyone, very appreciated :)
Post Reply