Cfimage inside a CFC

258 views Asked by At

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

2

There are 2 answers

2
Stephen Moretti On

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.

0
B S Nayak On

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.