0

I seem to be having an issue manipulating photos from within my CFC. I get an error that says that it encountered an exception while trying to read the image. So the question is pretty straightforward, are there any issues with manipulating files from within the CFC, rather than the CFM?

    <cffunction name="imageResize" access="public" returntype="boolean">

    <cfargument name="filename">
    <cfset result = "true">

    <cfimage
    action = "resize"
    source = "#root#/documents/uploads/PHOTOS/#filename#"
    width = "400px"
    height = ""
    destination = "#root#/documents/uploads/PHOTOS/thumbs/#filename#"
    overwrite = "yes"></cfimage>

    <cfreturn result>
    </cffunction>

Thanks

Leigh
  • 28,424
  • 10
  • 49
  • 96
aceslowman
  • 611
  • 11
  • 26
  • 2
    Have you tried running the same code in a CFM, rather than the CFC above, before blaming CFC? – Henry May 31 '12 at 18:03

2 Answers2

4

There are no issues with having cfimage inside a cfc. It's something I do all the time.

I suspect that the issue you have is that the variable "root" is unknown inside your function. You should probably also var scope your result variable and specify the scope on your use of the filename variable.

Stephen Moretti
  • 2,422
  • 1
  • 17
  • 29
  • Thanks! In that case, is there any problem with the way I am using "destination" if I want the resized image to be put in the thumbs folder? I couldn't find much that explained that attribute to me. – aceslowman May 31 '12 at 19:14
  • @AustinSlominski make sure `root` is what you expect it to be since it is not in arguments scope, and it could be now shared by multiple requests and this might not be what u want. – Henry May 31 '12 at 21:17
1

I have found quite a few issues with your code and have rectified them and it is working fine. Here are the issues.

  1. The function name 'imageResize' needs to be changed to some other name, because the function name provided by you is an existing coldfusion function.

  2. The width attribute in the cfimage tage need to have an integer like 420 not 420px.

  3. The source & destination attributes in the cfimage tag need to have absolute path like 'D:\projects\test' not like '/test/images'.

FYI: The 'root' variable you have mentioned in your code should be accessable in the function.

Here are the rectified code.

<cffunction name="imageResize2" access="public" returntype="boolean">
<cfargument name="filename">
<cfset result = "true">

<cfimage
action = "resize"
source = "D:\Projects\Test\images\#filename#"
width = "400"
height = ""
destination = "D:\Projects\Test\temp\#filename#"
overwrite = "yes" />

<cfreturn result>
</cffunction>

Yes, there are no issue in manupulating the files/images in cfc. The above code works both in cfs and cfm.

Bart
  • 18,467
  • 7
  • 66
  • 73
B S Nayak
  • 160
  • 11