Skip to main content
March 17, 2010
Question

cfimage and crop with direct links

  • March 17, 2010
  • 1 reply
  • 457 views

Hello,

I need some advice..

I want to have users reference images from my site but only certain sections (IE: http://somedomain.com/getimg.cfm?ID=123&section=1).  Below is the code I have but it only outputs a variable like coldfusion.image.Image@174e3a9 rather than the actual image.  I understand cfimage has a writeToBrowser action but that outputs html source which wont allow my users to have a direct link.

<cfprocessingdirective suppresswhitespace="yes">
<cfimage source="d:\test.jpg" name="myImage">
<cfset ImageCrop(myImage,0,0,534,474)>
<cfcontent type="image/jpeg" >
<cfoutput>#myImage#</cfoutput><!--- does not output actual image --->
</cfprocessingdirective>

    This topic has been closed for replies.

    1 reply

    Fernis
    Inspiring
    March 18, 2010

    You can also prevent direct links (although not fool-proof) by checking the HTTP_REFERER at http server level, using mod_write or isapi_rewrite (or similar). You can easily find examples for this by searching the internet.

    About cfcontent then... the correct usage would be <cfcontent variable="#myImage#" type="image/jpeg"> , but since cfcontent does not support a ColdFusion image object, but rather variables or binary objects read by cffile, save the cropped image to a disk with the cfimage tag, then read it using cffile.

    Better yet, if you are using ColdFusion 9, use the ram://-drive instead of physical disk for less I/O load.

    --

    - Fernis - fernis.net - ColdFusion Developer For Hire