【问题标题】:Issue with Lucee on Image write图像写入时 Lucee 的问题
【发布时间】:2019-03-29 01:55:55
【问题描述】:

我在 Lucee for Image Optimization 上遇到一个非常奇怪的错误,我将图像存储在 Mysql 数据库中的 BLOB

所以尝试这样做

我在 Lucee 中收到此代码的错误;

<cfset myImage = imageReadBase64(uploadimage_attachment)>
<cfimage action="write" overwrite="yes" destination="#ExpandPath('optimizeImagesDir/#id#.jpg')#" source="#myImage#">

这是错误:org.apache.commons.imaging.ImageReadException:Can't parse this format.

【问题讨论】:

  • 这是 CMYK 图像,还是可能通过 Photoshop 使用自定义颜色配置文件压缩?这在自定义图像格式中并不少见。
  • BLOB 是二进制的。 Base64 是一个字符串。也许您使用了错误的功能?

标签: coldfusion lucee


【解决方案1】:

看来,保存的数据不是有效的图像。可能您需要使用如下所示的插入查询(使用 queryparam 类型为 blob )。此外,您还需要使用imageGetBlob() 将数据转换为 BLOB。

<cfset obsolutePathOfImage = "D:/foo.jpg">
<cfset imageVariable = imageRead(obsolutePathOfImage)>
<cfquery datasource="test">
    INSERT INTO uploads( myimage )
    VALUES ( <cfqueryparam value="#imageGetBlob(imageVariable)#" cfsqltype="cf_sql_blob"> )
</cfquery>

最后您需要使用imageNew() 函数,以便从BLOB 数据创建图像变量。

<!--- "data" is the name of the query variable & "myimage" is the name of the DB column --->
<cfset filePath = D:/foo_from_DB.jpg>
<cfset myImageVar = imageNew(data.myimage)>
<cfimage action="write" overwrite="yes" destination="#filePath#" source="#myImageVar#">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多