Skip to main content
Inspiring
October 2, 2015
Question

ImageCrop suddenly stopped working

  • October 2, 2015
  • 2 replies
  • 3279 views

I have a cfm file that has been working for years on a remote shared server, which saves an uploaded image, crops it, resizes it and then saves it to a different folder as a thumbnail.

The upload save, get image metadata, resize, and save of resized file all work fine, but if I include the imageCrop line, then it fails silently at that point with no error.

It looks as though the imageCrop function is failing to load the image to manipulate it. But since everything else works, I can't think how this could be.

Anyone got any clues where I can look.

Doug

This topic has been closed for replies.

2 replies

James Moberg
Inspiring
October 2, 2015

What version of ColdFusion are you using?  If CF9, it could be failing because the uploaded JPG is CMYK. (If using CF10, valid CMYK images can still throw errors too.)  CMYK weirdness is the primary failure we've encountered when generating thumbnails.

As a result of CMYK bugs (and incredible slowness compared to alternatives), we've stopped using ColdFusion/Java for all image manipulation.  Do you have any control over what's installed on the remote server?  If so, consider installing GraphicsMagick as it processes more image types much faster (and is what Flickr uses.)

I've blogged about JPGs, ColdFusion, CMYK & GraphicsMagick here (including writing a CF9-11 Custom Tag):
http://gamesover2600.tumblr.com/search/graphicsmagick

NOTE: For thumbnail generation, we use CF_GraphicsMagick to perform an "aspect crop" with the following 1 line:

<CF_GraphicsMagick

     action="AspectCrop"

     Infile="#InFile#"

     outfile="#outFile#"

     width="440"

     height="260"

     result="imgData"

     quality="90">

doug777Author
Inspiring
October 4, 2015

Thanks for reply. We can certainly try your suggestion.

But I would still like to know what could have changed that suddenly made all our upload files that include imageCrop stop working when they had been working for years.

Doug

BKBK
Community Expert
Community Expert
October 2, 2015

Could you show us how you include the imageCrop line?

doug777Author
Inspiring
October 2, 2015

This is a test version of the file. If I comment out the cfif surrounding the imageCrop it all works. If it's in it fails with no error.

<cftry>

    <cfimage source="D:\inetpub\abcd\images\2DD425CD-9AED-4182-BBA6-DD6792FCA70BAmbassador.jpg" name="img">

    <cfset w = imageGetWidth(img)>

    <cfset h = imageGetHeight(img)>

    <cfif w/h LT 1>

        <cfset r = round((h-w)/2)>

        <cfset imageCrop(img, 0, r, w, w)>

    <cfelse>

        <cfset r = round((w-h)/2)>

        <cfset imageCrop(img, r, 0, h, h)>

    </cfif>

    <cfset imageResize(img, 54, 54)>

    <cfimage source="#img#" action="write" destination="D:\inetpub\abcd\images\thumbnails\2DD425CD-9AED-4182-BBA6-DD6792FCA70BAmbassador.jpg" overwrite="yes" quality="1">

    <cfcatch>

        <cfdump var="#cfcatch#" output="D:\inetpub\abcd\dumpfil.html" format="html">

    </cfcatch>

</cftry>

BKBK
Community Expert
Community Expert
October 2, 2015

doug777 wrote:

<cfif w/h LT 1>

        <cfset r = round((h-w)/2)>

        <cfset imageCrop(img, 0, r, w, w)>

    <cfelse>

        <cfset r = round((w-h)/2)>

        <cfset imageCrop(img, r, 0, h, h)>

    </cfif>

Case w/h < 1:

        The way you define r, it will be less than w only if h < 3*w. Otherwise the y-origin of the crop area will lie outside the image.

Case w/h >= 1:

        The way you define r, it will be less than h only if w < 3*h. Otherwise the x-origin of the crop area will lie outside the image.

In either case, you want the origin of the crop coordinates to lie within the picture. The correct condtions to achieve this are, respectively:

<cfif w/h LT 1 and h LTE 3*w>

<cfelseif w/h GTE 1 and w LTE 3*h>

You can see from this that:

1) when w/h < 1, the crop formula, r = round((h-w)/2), is valid only if 1/3 < w/h < 1;

1) when w/h > 1, the crop formula, r = round((w-h)/2), is valid only if 1/3 < h/w < 1;