When scaling are pixel sizes always rounded UP?

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
pdc
Posts: 3
Joined: 2014-09-01T04:46:21-07:00
Authentication code: 6789

When scaling are pixel sizes always rounded UP?

Post by pdc »

Here's a quick dumb question for you:

Given an image with dimensions 1600 by 900, when I resize it with -resize 500x500> then I get an image that is 500 by 282. That is, the height is rounded up to the nearest pixel rather than rounded to the nearest whole pixel (which would have been 281). In my app I need to be able to predict the scaled image size given the source size and the bounding box without loading the file.

Can I assume that for output images, fractional sizes are always rounded up?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: When scaling are pixel sizes always rounded UP?

Post by snibgo »

What version of IM, on what platform?

On IM v6.8.9-5, Windows 8.1, I get 281:

Code: Select all

F:\prose\PICTURES>%IM%convert -size 1600x900 xc: -resize 500x500 info:

xc: XC 500x281 500x281+0+0 16-bit sRGB 0.547u 0:00.077
I'm not sure it is wise to make assumptions about how IM will round numbers. I would either specifiy the exact dimensions I want, or leave it up to IM and then find out what it has done.
snibgo's IM pages: im.snibgo.com
pdc
Posts: 3
Joined: 2014-09-01T04:46:21-07:00
Authentication code: 6789

Re: When scaling are pixel sizes always rounded UP?

Post by pdc »

snibgo wrote:What version of IM, on what platform?

On IM v6.8.9-5, Windows 8.1, I get 281:
Thanks, snibgo. It looks like I need to pass my calculated dimensions to ImageMagick explicitly rather than trying to make my calculation match ImageMagick’s.
pdc
Posts: 3
Joined: 2014-09-01T04:46:21-07:00
Authentication code: 6789

Re: When scaling are pixel sizes always rounded UP?

Post by pdc »

Correcting myself …

Where I was going wrong was sometimes when resizing a large image in to N different sizes we used one of the biggish resized images to make the smaller ones instead of the massive source image: this naturally leads to rounding errors so that the final size does not match the size calculated from the original dimensions.

Solution is as described above—calculate the final size (which we needed to do anyway) and use `-resize 500x281!` in preference to `-resize 500>` or whatever.
Post Reply