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#">
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.
Archived Comments
Did Adobe explain why the color space change would "fix" this? It makes no sense to me. ARGB just adds the ability to have an alpha channel for transparency.
Now i dont know anything about these new funcitons and have not read the documentation, but i a suggestion to try.
Why specify the ImageSetDrawingColor on your second line of code? I think this is what is causing the black to show when you rotate it. Try switching to white before the rotate. Or finding a new way of defining the text color.
I would think that the function ImageDrawText would take a color attribute to defined the color of the text you are drawing.
Cant wait to get my hands on CF8! Love the new features so far!
Maybe a really stupid question but is the text-rendering of the ImageDrawText function in cleartype or bitmap?? I'm really excited about this because I was playing with the gFont cfx tag of efflare and if this function is already in CF8 I don't need this cfx tag.
@Ray,
Have you tried setting the image's background color and clearing a rectangle before the rotation?
ImageSetBackgroundColor(image, color)
ImageClearRect(image, x, x, width, height)
Tom: I tried the first one, it didn't help, and in theory, shouldn't be necessary. When I used the imageNew and specified a BG color, that should have did it.
The problem is with the imaging library that we are using here. We are checking if we can get a solution or workaround that can help here.
In principal what interpolation does is take a set of pixels around the source pixel to determine the target pixel. For exampl, nearest will take least number of pixels around source to determine target.
Thanks,
Hemant
Hi Ray,
I'm a turtle and have just reached this post :)
ImageRotateDrawingAxis(textImage,30) before ImageDrawText() could be a temporary alternative.
Then ImageRotate() is not needed here.
cheers
-terry
This may be a stupid question, but why can I not get this to work. I am using CFMX 8, i paste your code in and I get nothing... Any test code I try, i get nothing. Its enabled in the admin, but I can not get anything regarding CFIMAGE to work.. Any tips on making sure CFIMAGE will work?
So you can't get any cfimage stuff to work at all? Did you try other examples?
When I rotate an image and then write to file, it seems like the image file size is reduce even after I set the quality of the imagewrite to the highest value for quality. Is there any tip on how to make the image quality remain the same, after I rotate and save an image file?
Thanks.
If you are setting the quality to the highest, then that's all I can recommend for now. Have you tried it with 8.0.1?
To get rid of the black around the edges you need to have a border of transparency around the image. In other words, you need to have a transparent image and no part of that image can touch a border.
Have you noticed that your image didn't rotate by 30 degrees, but by just 2 degrees. I've found that when using the x and y parameters I have to the the rotation AFTER them.
Anyone else noticed this?
I thought maybe it was just a bad screen shot, but I can't test this now as my local Apache server doesn't seem to be serving up cfimage correctly. I'll need to fix that I suppose.
Ok, got a test working. So - yeah - this is weird. When I do just 30, it is really obvious. When I do 30,2,2 - it is different - but the specs say 2,2 is the X/Y is the default.
I'll file a bug report.