ColdFusion 8: Image Rotate Tip

I was playing with image rotation last night (I know, call me Mr. Excitement), and I found an interesting issue. Consider this code: <cfset textImage=ImageNew("",200,200,"rgb","white")>

<cfset ImageSetDrawingColor(textImage,”black”)>

<cfset attr=StructNew()> <cfset attr.size=30> <cfset attr.style=”bold”> <cfset attr.font=”ArialMT”>

<cfset ImageSetAntialiasing(textImage, “on”)> <cfset ImageDrawText(textImage,”Paris”,50,75,attr)>

<cfset ImageRotate(textImage,30,2,2)>

<cfimage action=”writeToBrowser” source=”#textImage#”> </code>

I create a new blank image and then draw some black text and then rotate. I end up with this:

Notice the black background? I tried to fix it by using this for my image:

<cfset textImage=ImageNew("",200,200,"rgb","white")>

But it had no impact. Luckily I got some help from Adobe (thank you Hemant!) and he mentioned that if I switch my image type to ARGB instead of RGB, it will work. With that, I got this:

Not bad - but a bit ugly. The imageRotate function takes a 5th argument: interpolation. This basically sets the quality of the rotation. Adobe defaulted to the quickest method, “nearest.” Switching to the highest, “bicubic”, makes a real pretty rotation, but the leaves some “crud” on the sides:

Of course, I could crop that easily enough, but, still, a bit of a problem. The middle ground interpolation, bilinear, also leaves the same.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments