January 26, 2008
I am currently porting a website from classic ASP into CF8 and one of the features that this site had was an automatic generation of thumbnails; so I used the wonders of CFImage (and some caching know-how to decrease the performance hit) to implement this, but then I ran into a very annoying limitation of CFImage, namely the inability to handle certain jpeg images.
For some images, whenever I attempted to read them from the file system using CFImage I would get the following error back:
The weird thing was that I could see these images in the browser without a problem, and they even appeared as regular jpeg images. Then I remembered about progressive jpeg images, which is a particular type of JPGs but are designed to be displayed as if the image quality increases as it is being loaded.
However pjpeg is not one of the readable types by ColdFusion, so after some tinkering around, I found an interesting thing and I'm not sure if this is a bug in CFImage or not: Reading one of these images using
So I modified my thumbnail generation script so that whenever it finds one of these unreadable JPG images, it will then read the binary contents of the image, create a new image using the image data and then overwrite the source image with the newly created image, resulting in a normal JPEG image that can now be read without problems.
The relevant part of the script is this:
href is the location of the image in the site. Hopefully someone will find this useful.