ImageNew toBase64编码问题,ColdFusion质量下降(ImageNew toBase64 encoding issue with loss of quality in ColdFusion)

我一直遇到toBase64()的问题。 我希望有人可以告诉我为什么CF toBase64()似乎丢失了一些东西,即在我的例子中它降低了图像的质量。

我有一个解决方案(参见下面的最后一个代码示例),但我不想理解为什么并且愿意解决这个问题。

如果有人会如此善良地运行下面的代码,那么你会看到在toBase64转换后,图像质量很差。 没什么大不了的,但编码后看起来不太好。 如果你从未注意到,那么试试吧,你会明白我的意思。

有谁知道为什么,或者如何在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 --->

我的解决方案是使用java附加组件,一切似乎都没问题,但由于原因,我不会进入这里,而不是我可以做的事情。

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

上面代码的示例图像输出可以在这里找到: http ://i56.tinypic.com/29fwiq.png首先是在toBase64秒之后,你可以看到图像在第二个输出上的toBase64函数后丢失了一点质量。

更新:正如Peter所指出的,问题似乎在于ImageObject中的自动输出/转换代码,以便为toBase64函数提供二进制输出以进行编码。

更新我已将此作为CF 9.0.1中的错误提交,请投票给错误3177303 https://bugbase.adobe.com/index.cfm?event=bug&id=3177303

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

最满意答案

使用toBase64(imageGetBlob(myImg))

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

use toBase64(imageGetBlob(myImg))

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

更多推荐