【问题标题】:An exception occurred while trying to read the image尝试读取图像时发生异常
【发布时间】:2016-08-16 13:35:35
【问题描述】:

这很好用:

<cfset image="http://netdna.webdesignerdepot.com/uploads/2008/11/sample-graphic.jpg">
<cfimage action="INFO" source="#image#" structname="objImageInfo" name="myImage">

这给出了一个错误:

<cfset image="http://www.freedigitalphotos.net/images/img/homepage/87357.jpg">
<cfimage action="INFO" source="#image#" structname="objImageInfo" name="myImage"> 

尝试读取图像时发生异常。 Coldfusion.image.ImageReader$ImageReadingException:尝试读取图像时发生异常。

为什么?

【问题讨论】:

  • 图像功能和错误修复在版本 8 和 11 之间存在很大差异。您使用的正是 哪个版本会引发该错误?
  • 我认为这里的问题是 freedigitalphotos.net 有某种形式的热链接保护。他们可能会阻止来自无效用户代理或请求的请求。如果您查看错误,它可能会告诉您它在该图像上返回 403 Forbidden。
  • 好收获。如果您阅读了 full 错误消息,那就是问题所在。 @EduardClimov - 我没有投反对票,但正如your last question 中提到的,请帮助我们为您提供帮助;-) 许多事情会因版本而异,因此请使用标签来指明您正在使用的具体版本。跨度>
  • 感谢您的帮助!下次我会指出我的版本,@Leigh :)
  • 我很好奇这个。当我在 CF10 上使用 IsImageFile() 检查两个 URL 时。检查时 isImageFile("netdna.webdesignerdepot.com/uploads/2008/11/…) 结果给出“是”,而 isImageFile("freedigitalphotos.net/images/img/homepage/87357.jpg") 结果给出“否”。我认为这可能是该网站有一些访问限制。

标签: coldfusion coldfusion-9 coldfusion-10 coldfusion-8 coldfusion-11


【解决方案1】:

我们可以使用“ReadBinary”操作将图像读取为二进制数据,然后使用“INFO”操作获取图像信息。代码应如下所示..

<cfif not isImageFile("http://www.freedigitalphotos.net/images/img/homepage/87357.jpg")>

   <cffile action="readbinary" file="http://www.freedigitalphotos.net/images/img/homepage/87357.jpg" variable="strFile">
   <cfset oImage = imageNew(strFile)>   
   <cfimage action="INFO" source="#oImage#" structname="objImageInfo" name="myImage">  

   <cfdump var="#objImageInfo#" /> 
</cfif>

我在这里找到了这个解决方案。http://www.oscararevalo.com/blog/index.cfm/2008/1/26/cfimage-and-pjpeg-images

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多