"Missing Huffman code" Error Using ImageWrite()

I've been having troubles with thumbnail generation on one of my apps recently.  Just sporadically, with no obvious pattern as to why.  The error is about a missing Huffman code (used for JPEG compression).  Turns out that certain images when being written at certain sizes, throw this error when you use the built-in imageWrite().

The solution is to skip the CF solution and manually do it the Java way.  So what used to be this:

<cfset imageWrite(image, filename) />

now looks like this:

<cfset createObject("java", "javax.imageio.ImageIO").write(
   imageGetBufferedImage(image),
   "jpeg",
   createObject("java", "java.io.File").init(filename)
) />

Fortunately, Adobe had the foresight to include the wonderfully named imageGetBufferedImage() built-in so you can access the raw image data with the native Java APIs.  Note that with the Java you have to specify the encoding type explicitly, instead of letting CF figure it out based on the filename's extension.  Since I'm only dealing with JPEG images, I just hard coded it.

One response to “"Missing Huffman code" Error Using ImageWrite()”

  1. Justice

    There is also a hotfix that patches this issue, you can find it at http://kb.adobe.com/selfservice/viewContent.do?externalId=kb402604&sliceId=1

    Chris