Note that there are some explanatory texts on larger screens.

plurals
  1. POcrop an image from the centre using coldfusion
    primarykey
    data
    text
    <p>This is my first bit of programming in quite a while, so I'm basically starting from scratch, and I'm using coldfusion 8. </p> <p>What I'm trying to do is create a series of uniform thumbnail images (always 68 X 46) from a variety of larger images, some portrait, some landscape. In both cases resizing the image to fill the height or width of the thumbnail and then cropping the excess image equally off either side (top/bottom, left/right). Just as photoshop does by default with canvas resize.</p> <p>The code below works really well as long as the source images dimensions/ratio is perfect, but I've started to run into cases where the code fails. In this case, when a resized images width ends up being less than 68. </p> <pre><code>&lt;cfif FileExists(ExpandPath('images/gallery/thumbs/thm_'&amp;imageMed[i].medium.XmlText)) IS false&gt; &lt;!--- If the thumb doesn't exist, create it. ---&gt; &lt;cfif imageDataThumb.width gt imageDataThumb.height &gt; &lt;!--- Landscape ---&gt; &lt;cfset ImageResize(cfImageThumb,"","46")&gt; &lt;cfset ImageCrop(cfImageThumb,(cfImageThumb.width-68)/2,0,68,46)&gt; &lt;!--- Crop left/right edges of images ---&gt; &lt;cfimage source="#cfImageThumb#" action="write" destination="images/gallery/thumbs/thm_#imageMed[i].medium.XmlText#" overwrite="yes"&gt; &lt;cfelse&gt; &lt;!--- Portrait ---&gt; &lt;cfset ImageResize(cfImageThumb,"68","")&gt; &lt;cfset ImageCrop(cfImageThumb,0,(cfImageThumb.height-23)/2,68,46)&gt; &lt;!--- Crop top/bottom edges of images ---&gt; &lt;cfimage source="#cfImageThumb#" action="write" destination="images/gallery/thumbs/thm_#imageMed[i].medium.XmlText#" overwrite="yes"&gt; &lt;/cfif&gt; </code></pre> <p> </p> <p>Trying to solve these "edge cases" is turning the code into a mess. Is there a better way to approach this? Something in coldfusion or a cfc?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload