Skip to main content
November 20, 2008
Question

Image Resize

  • November 20, 2008
  • 3 replies
  • 588 views
I am using cfscript tag to write code that resizes an image and writes it on a certain folder. See code below.

<cfscript>

myImage = ImageNew(ExpandPath(cover_url));
ImageResize(myImage,"100","","lanczos");
ImageWrite(myImage,'#ExpandPath(thumb)#/#ListLast(cover_url,"/")#');

</cfscript>

I am not so sure how I can check if the resized photo already exist, before resizing it again. If it exist, I'd like to rename the new file name so it is unique or just don't overwrite the resized copy at all.

Thanks,

Ngu
    This topic has been closed for replies.

    3 replies

    November 21, 2008
    Yes, the function is fileExists().

    Also, don't forget to scope your myImage variable.

    <cfscript>
    var myImage = "";
    myImage = ImageNew(ExpandPath(cover_url));
    ImageResize(myImage,"100","","lanczos");
    ImageWrite(myImage,'#ExpandPath(thumb)#/#ListLast(cover_url,"/")#');

    </cfscript>

    Mikey.
    BKBK
    Community Expert
    Community Expert
    November 20, 2008
    The function you're looking for is fileExists(absolute_path_to_file).

    Inspiring
    November 20, 2008
    alexmurphy wrote:
    >
    > I am not so sure how I can check if the resized photo already exist, before
    > resizing it again.

    The fileExists() function could probably help with that.