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?
When scaling are pixel sizes always rounded UP?
-
- 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?
What version of IM, on what platform?
On IM v6.8.9-5, Windows 8.1, I get 281:
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.
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
snibgo's IM pages: im.snibgo.com
Re: When scaling are pixel sizes always rounded UP?
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.snibgo wrote:What version of IM, on what platform?
On IM v6.8.9-5, Windows 8.1, I get 281:
Re: When scaling are pixel sizes always rounded UP?
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.
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.