Base64 Image Converter - CFBuilder Extension

I took all that Base64 image conversion stuff I have been talking about and turned it into a CFBuilder extension. I also submitted it to the CFBuilder extension contest.

Review of extension by Ray Camden: CFBuilder Contest: Base64 Image Converter

Get the Extension: http://base64imageconverter.riaforge.org/

Till next time...

--Dave

All your base64 are not equal

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
1<cfscript>
2    myImg = imageRead('grayButton.png');
3    writeDump(toBase64(myImg));
4
</cfscript>

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.
2
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
1<cfscript>
2    myImg = imageRead('grayButton.png');
3    ImageWriteBase64(myImg,"ram:///Base64.txt","png","yes", true);    
4
    a = fileRead("
ram:///Base64.txt");
5
    fileDelete("ram:///Base64.txt");
6
    writeDump(a);
7</cfscript>

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...

--Dave

Creating Base64 images with ColdFusion

I have been working on recreating a website to make it iPhone compliant. In doing this I have been investigating numerous ways to reduce calls to the server. In some demo code I had I saw an image load using a Base64 image. This intrigued me and I investigated this further.

I was able to convert all the navigational images in the site to Base64. This reduced the overall loading call count from 300 to 5. However, the CSS file was much larger. But even still, the overall load time was reduced by over 50%.

There are numerous advantages and disadvantages do using this technique. The first large one is browser support. Since I was targeting the iPhone, this method works fine. However, IE only supports this with v8 and limited support at that. Read more about the pros/cons here.

[More]