ColdFusion 9 PNG image processing

Recently, I was doing some work on an internal system where I was doing some image processing. I was taking uploaded images and resizing them into a smaller preview image on request. The code for this is quite simple.

view plain print about
1<cfimage action="read" source="testimg.png" name="myImg">
2<cfimage action="resize" height="150" source="#myImg#" width="150">
3<cfimage action="writeToBrowser" source="#myImg#">

However, when running the code it was taking between 30-60 seconds to run. I tried a bunch of different things to get it to work correctly. I even rewrote it in cfscript to see if that would help. Well, it didn't, no difference. The processing till took forever.

At this point I opened up the ColdFusion server monitor. The monitor will allow me to see what the request is actually getting stuck on. With the monitor running I ran the code again a few times. Once normal, and another with the image resize code commented out. The monitor showed me that the code was indeed getting stuck on the resize.

I then started looking at the source images. The images were all under 1mb so size issue was now out. On a whim I ran a test using a jpg image. This time the image processed immediately. Returned in under a second and resized as expected.


Creating text image with ColdFusion 8

I thought this would be a trivial task. Create an image based on some text. I wanted the image to be the size of the text. I also wanted the image to be transparent. Sounds straight forward and not very complicated considering I have cfimage at my disposal.

However, in attempting to do this I found it to be rather complicated. The process to figure out the text size and then size the image is not so trivial. Then creating the transparency was another challenge.

Lucky I had done part of this before. I previously created a process to watermark images with cfimage. Thankfully I was able to take that code and re-purpose it for what my new need.