这是我很长一段时间以来的第一次编程,所以我基本上是从零开始,我使用的是coldfusion 8。
我想做的是从各种较大的图像、一些肖像、一些风景中创建一系列统一的缩略图图像(总是 68 X 46)。在这两种情况下,调整图像大小以填充缩略图的高度或宽度,然后将多余的图像从任一侧(上/下,左/右)平均裁剪。就像 Photoshop 默认使用画布调整大小一样。
只要源图像尺寸/比例完美,下面的代码就可以很好地工作,但是我已经开始遇到代码失败的情况。在这种情况下,当调整大小的图像宽度最终小于 68 时。
<cfif FileExists(ExpandPath('images/gallery/thumbs/thm_'&imageMed[i].medium.XmlText)) IS false> <!--- If the thumb doesn't exist, create it. --->
<cfif imageDataThumb.width gt imageDataThumb.height >
<!--- Landscape --->
<cfset ImageResize(cfImageThumb,"","46")>
<cfset ImageCrop(cfImageThumb,(cfImageThumb.width-68)/2,0,68,46)> <!--- Crop left/right edges of images --->
<cfimage source="#cfImageThumb#" action="write" destination="images/gallery/thumbs/thm_#imageMed[i].medium.XmlText#" overwrite="yes">
<cfelse>
<!--- Portrait --->
<cfset ImageResize(cfImageThumb,"68","")>
<cfset ImageCrop(cfImageThumb,0,(cfImageThumb.height-23)/2,68,46)>
<!--- Crop top/bottom edges of images --->
<cfimage source="#cfImageThumb#" action="write" destination="images/gallery/thumbs/thm_#imageMed[i].medium.XmlText#" overwrite="yes">
</cfif>
试图解决这些“边缘情况”会使代码变得一团糟。有没有更好的方法来解决这个问题?冷熔或 CFC 中的东西?