Skip to main content
Known Participant
March 5, 2008
Question

ImageResize Off by 1px

  • March 5, 2008
  • 2 replies
  • 810 views
When using ImageResize it can be off by 1px in height, width or both. If I specify the "interpolation" as "highestPerformance" it resizes correctly but with "highestQuality" (which is prefered) the image is off 1px.

This doesn't happen every time, it depends on the starting width and height if it is off.

Is there a hot fix for this, is there any way (other than highestPerformance) to get that to work and look good?

Thanks.
This topic has been closed for replies.

2 replies

dbldutchAuthor
Known Participant
March 6, 2008
I did not see anything related to that so I'll submit it. Thanks again.
Inspiring
April 5, 2008
Just an update. The issue is now included in the Known Issues section of the Release notes for the recent ColdFusion 8 Update 1.

70069
Sometimes the ImageResize function produces an image 1 pixel shorter or
narrower than the requested size. The image does resize properly if you
specify bicubic, bilinear, nearest, or highestPerformance as the
interpolation parameter value.
Inspiring
March 6, 2008
Can you give an example that reproduces this problem?
dbldutchAuthor
Known Participant
March 6, 2008
Sure, no problem.

The image I started with was 1280x960 at 72dpi.

<cfimage source="d:\projects\test.jpg" name="img">
<cfscript>
ImageSetAntialiasing(img, "on");
ImageCrop(img, 66, 270, 458, 229);
ImageResize(img, 100, 50);
</cfscript>
<cfimage source="#img#" action="write" destination="d:\projects\test-thumb.jpg" quality=".85" overwrite="yes">

The user would click on the image to come up with x, y, w and h values.

Thanks for the help
Inspiring
March 6, 2008
Yes, that seems like a rounding problem. Christian Küpers mentioned something about this on Ben Nadel's blog. I do not know if the math works out in every case, but notice how incrementing the value slightly produces a 100x50 image, instead of 99x49? That seems to support the theory it is a rounding problem.

ImageResize(img, 100.0001, 50.0001);