ImageNew toBase64 encoding issue with quality loss in ColdFusion

I had problems with toBase64 () for a while. I hope someone tells me why CF toBase64 () seems to be missing something, i.e. in my example, this reduces image quality.

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

If someone is so kind as to run the code below, you will see that after toBase64 conversion, the image quality is poor. Nothing serious, but after encoding it doesnโ€™t look so good. If you have never noticed this, try, you will understand 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 the java add-in, and everything seemed fine, but for reasons that I will not go into, I canโ€™t live live.

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

An example of outputting the image with the code above can be found here: http://i56.tinypic.com/29fwiq.png First, before toBase64 appears after the second, you can see that the image has lost some quality after the toBase64 function on the second output.

Update: As Peter noted, the problem is with the automatic output / conversion code in ImageObject to provide binary output for the toBase64 function for encoding.

Update I presented this as an error in CF 9.0.1, vote for error 3177303 https://bugbase.adobe.com/index.cfm?event=bug&id=3177303

+4
source share
2 answers

I see no one has mentioned the imageWriteBase64 () function that has been in ColdFusion since version 8. I donโ€™t know why.

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-796b.html

I am using it for the first time this week, and it seems to be great. I did not notice any problems with quality loss.

 <cfdirectory action="list" directory="#expandPath('./images')#" name="imageDir" type="file" /> <cfloop query="imageDir"> <cfset ext = listLast(imageDir.name, ".") /> <cfset name = imageDir.name /> <cfset imagePath = imageDir.directory & "/" & name /> <cfset imageFile = imageNew(imagePath) /> <cfset imageWriteBase64(imageFile,"#expandPath('./base64')#/#name#.txt",ext, true) /> </cfloop> 
+1
source

Source: https://habr.com/ru/post/1380177/


All Articles