This might not be news to anyone else, but I never actually thought about the coordinates used in ColdFusion image manipulation functions. I am so used to everything in ColdFusion being one-based that I just assumed that ColdFusion image manipulation would work the same way. Well, as I was working on updating the ImageUtils.cfc, I realized that I was way off base (thanks to OutOfBounds errors getting thrown left and right). As it turns out, ColdFusion image objects are zero-based when it comes to pixel coordinates. To test this, I ran some of ColdFusion 8's X/Y based methods:
<!--- Create 10x10 image. ---> <cfset objImage = ImageNew( "", 10, 10, "argb", "##262626" ) /> <!--- Copy based on zero-based coordinates. ---> <cfset objImage2 = ImageCopy( objImage, 0, 0, 10, 10 ) /> <!--- Crop image based on zero-based coordinates. ---> <cfset ImageCrop( objImage2, 0, 0, 5, 5 ) /> <!--- Draw rectangle using zero-based coordinates. ---> <cfset ImageDrawRect( objImage2, 0, 0, 5, 1, "yes" ) /> <!--- Draw line using zero-based coordinates. ---> <cfset ImageDrawLine( objImage2, 0, 0, 50, 50 ) />
As you can see, things like ImageCopy(), ImageCrop(), ImageDrawRect(), and ImageDrawLine() all work with zero-base coordinates. Ok, in all fairness, I believe that ImageDrawRect() and ImageDrawLine() will actually work with off-canvas values; however, ImageCrop() will throw an OutOfBounds error if you try to go off canvas.
So, there you have it - ColdFusion image manipulation is zero-based, not one-based. This isn't hugely important information, but there are some things that I will have to go back and fix in the ImageUtils.cfc where some one-to-zero base calculations take place.
Want to use code from this post? Check out the license.