0

我正在coldfusion8/mysql 5.0.88使用 Jquery Mobile 的前端创建一个站点。我还使用了photoswipe.js插件,它允许在单独的视图层中缩放和浏览图像。

要设置 photoswipeable 图像,我需要输出

<cfoutput>
<a class="swipeMe" rel="external" href="#variables.imageSrc#">
    <img src="#variables.imageSrc#" class="adaptImg ui-li-thumb" />
</a>
</cfoutput>

问题是imageSrc由用户提供的,因此我必须在显示图像之前抓取/验证/调整图像大小,并且我需要照片滑动链接的图像路径。

我一直在摆弄这个,并提出了以下解决方案:

 // read img from user specs
 <cfimage name="myImage" source="#bildpfad##bilddateiname#" action="read" />
 <cfif IsImage(myImage) is true>
      // resize
      <cfscript>
           ImageSetAntialiasing(myImage,"on");
           variables.breite = 400;
           ImageScaleToFit(myImage, variables.breite,"", "highestPerformance");
      </cfscript>
      // write to xml, so I can get the path
      <cfxml variable="imageXml">
           <cfimage quality=".5" action="writetobrowser" source="#myImage#" class="adaptImg ui-li-thumb"/
      </cfxml>
      <cfset variables.imageSrc = imageXml.xmlRoot.xmlAttributes.src>
      // output
      <cfoutput>
         <a class="swipeMe" rel="external" href="#variables.imageSrc#">#imageXml#</a>
      </cfoutput>
 </cfif>

虽然这很有效,但它几乎使应用程序停滞不前,而且内存似乎也泄漏了,因为我在运行它时失去了越来越多的内存。

问题
上述代码是否有任何明显的问题导致内存泄漏?我想象图像正在被写入某种临时目录(CFFileservelet?​​)并在那里停留一段时间阻塞我的记忆。如果是这样,在图像搜索中处理这个问题的替代方法是什么?

谢谢!

4

1 回答 1

2

为什么不在您的服务器上创建一个 /tmp 文件夹,然后在其中写入经过处理的图像,例如:

<cfset newImageName=CreateUUID()&".jpg">
<cfimage action="write" destination="/tmp/#newImageName#" source="#myImage#">

然后你可以使用它:

  <cfoutput>
     <a class="swipeMe" rel="external" href="/tmp/#newImageName#"><img src="/tmp/#newImageName#" class="..."></a>
  </cfoutput>

用于删除临时文件的示例计划任务:

<cfdirectory action="LIST" directory="#expandpath('tmp/')#" name="tempfiles" filter="*.jpg">
<cfloop query="tempfiles">
    <cfif dateadd('h',24,dateLastModified) lt now()>
        <cffile action="DELETE" file="#expandpath('tmp/')##name#">
    </cfif>
</cfloop>
于 2012-08-24T13:27:07.860 回答