I responded to a question yesterday on the adobe forums that reminded me of a problem I had with ImageGetBlob a few weeks ago. I was surprised to discover the function does not seem to work with GIF images. Now perhaps I overlooked it, but I do not remember the documentation mentioning that ImageGetBlob does not support GIF's. Anyway, when I tried using ImageGetBlob on a GIF image ColdFusion returned this error
An error occured in converting the image to base64 in the required image encoding. Base64 images can be created with ColdFusion in BMP,JPEG,PNG,PNM,and TIFF formats
The solution I came up with was to use the ImageIO class to write the data to a ByteArrayOutputStream and then use the toByteArray() method to grab the image bytes.
// read in a sample image
pathToImage = ExpandPath("MyGIFImage.gif");
imageExtension = listLast(pathToImage, ".");
img = ImageNew( pathToImage );
// extract underlying BufferedImage
buffered = ImageGetBufferedImage(img);
// write out image bytes
ImageIO = createObject("java", "javax.imageio.ImageIO");
outStream = createObject("java", "java.io.ByteArrayOutputStream").init();
ImageIO.write( buffered, imageExtension, outStream );
imageBytes = outStream.toByteArray();
Note, this method requires that a compatible image writer is registered. You can view the informal format names understood by the registered writers using static methods of the ImageIO class.
<cfset ImageIO = createObject("java", "javax.imageio.ImageIO")>
While this works, I would be interested to hear if anyone else has come up with a different or simpler method.