Yesterday I blogged about a base64 image creator I built. Today I was working to do more image conversion to base64 for my project. I quickly ran into an issue on my ColdFusion 9 server.

Source image

I was using this code to get the base64 of the image:

view plain print about
2    myImg = imageRead('grayButton.png');
3    writeDump(toBase64(myImg));

But it threw this error:

view plain print about
1The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code.
3Null Pointers are another name for undefined values.

I was using this method because "imageWriteBase64()" only writes out to a file. I have no use / need / or want for a file. I want the result. So, using ColdFusion 9 I was able to avoid writing a file to the disk but still get the result. The solution utilizes the in-memory file system.

view plain print about
2    myImg = imageRead('grayButton.png');
3    ImageWriteBase64(myImg,"ram:///Base64.txt","png","yes", true);    
    a = fileRead("

This solution seems totally wrong to me. First, why does toBase64() throw a null error. The source is obviously good as imageWriteBase64() can process it. Also, why is the only possible result from imageWriteBase64() is to write a file. Granted the function name contains imageWrite but it still seems wrong.

Till next time...