Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageNew toBase64 encoding issue with loss of quality in ColdFusion

I have been having problems with toBase64() for awhile. I am hoping someone can tell me why CF toBase64() seems to lost something i.e. in my example it reduces the quality of an image.

I have a solution (see last code example below), but I hate not understanding why and would love to solve this is CF.

If anyone would be so kind to run the code below, you would then see that after toBase64 conversion the image quality is bad. Nothing major, but it does not look as good after the encoding. If you have never noticed, then try it, you will see what I mean.

Does anyone know why, or how to solve this in CF?

<!--- EXAMPLE 1 --->

<!--- GET IMAGE - --->
<cfset image = ImageNew("test.png")>
<!--- BEFORE GOOD--->
<cfimage action="writeToBrowser" source="#image#" >
 <cfset image = toBinary(toBase64(image)) />
 <!--- AFTER --->
<cfimage action="writeToBrowser" source="#image#" >

<!--- Example 2 --->
<cfset image = ImageNew("test.png")>
<cfset FileWrite(expandPath('./converted.image'),toBinary(toBase64(image))) />
<!--- without any cfimage processing, the outputted file is a JPEG --->


My solution was to use a java add-on and everything seemed ok but for reasons I won't go into here not something I can do live.

image = createObject("java","it.sauronsoftware.base64.Base64").encode(image);
 toBinary(image );

Sample image output of code above can be found here: http://i56.tinypic.com/29fwiq.png First is before toBase64 second is after, you can see the image has lost a bit of quality after toBase64 function on the second output.

Update: As pointed out by Peter, the issue seems to be with the automatic output/conversion code within the ImageObject to provide the binary output for the toBase64 function to encode.

Update I have submitted this as a bug in CF 9.0.1, please vote for bug 3177303 https://bugbase.adobe.com/index.cfm?event=bug&id=3177303

like image 854
Prometheus Avatar asked Oct 09 '22 13:10

Prometheus


1 Answers

use toBase64(imageGetBlob(myImg))

see: http://blog.dkferguson.com/index.cfm/2010/4/27/All-your-base64-are-not-equal

like image 191
Henry Avatar answered Oct 13 '22 10:10

Henry