Skip to main content
WebolutionDesigns
Known Participant
August 6, 2010
Question

CFIMAGE CFLOOP Performance

  • August 6, 2010
  • 1 reply
  • 746 views

I have a site I am building that pulls large images from a folder based upon a recordset. I am using cfimage within a cfloop to go through the recordset, resize the images and add a watermark. I am experiencing performance problems. I was thinking that perhaps cfthread might be useful in this scenario, but I have not used that before. Anyone have thoughts on how to solve my performance issues?

FYI...here is my current cfloop/cfimage code for your reference.

<cfloop query="rsProofs">

<!--- Read in the original image. --->

    <cfset objImage = ImageRead( "./proof/#rsProofs.FILENAME#" ) />

    <!--- Read in the Stark Images watermark. --->

    <cfset objWatermark = ImageNew( "./images/logoMain.png" ) />

    <!---Resize main image--->

    <cfimage action = "resize" height = "10%" source = "#objImage#" width = "10%" overwrite = "no" name = "objImageresize">

    <!---Resize watermark image--->

    <cfimage action = "resize" height = "75%" source = "#objWatermark#" width = "75%" overwrite = "no" name = "objWatermarkresize">

    <!---Rotate watermark--->

    <cfimage action = "rotate" angle = "-35" source="#objWatermarkresize#" overwrite="no" name="objWatermarkrotate">

    <!---

        Turn on antialiasing on the existing image

        for the pasting to render nicely.

    --->

    <cfset ImageSetAntialiasing( objImageresize, "on" ) />

    <!---

        When we paste the watermark onto the photo, we don't

        want it to be fully visible. Therefore, let's set the

        drawing transparency to 50% before we paste.

    --->

    <cfset ImageSetDrawingTransparency( objImageresize, 60 ) />

    <!---

        Paste the watermark on to the image. We are going

        to paste this into the bottom, right corner.

    --->

    <cfset ImagePaste( objImageresize, objWatermarkrotate, 50, 0 ) />

<!--- Write it to the browser. --->

    <p><cfimage action="writetobrowser" source="#objImageresize#" /></p>

            <hr />

</cfloop>

Thanks,

Clay

This topic has been closed for replies.

1 reply

Inspiring
August 6, 2010

Image manipulation tends to be resource/time intensive any way you look at it. Especially when there is a lot of it occurring, like within a loop. Do you really need to watermark on the fly, or this something that could be done only once?

On a side note, if you are reusing the same watermark each time you should resize / rotate it before you enter the loop. So you are only manipulating it once, not once for each loop.

WebolutionDesigns
Known Participant
August 6, 2010

I pulled the watermark out. That was a good suggestion. Now...how would I go about looping through the query using threads and then rejoining them?

Inspiring
August 6, 2010

Without knowing much about the process, it is hard to say if cfthread will help or harm here. For things like single watermarks or thumbnails, it is often more efficient to perform the operation only once as images are added/uploaded. Rather than repeating them on each request.

However to answer your question, there are some very thorough blog entries on the topic of using cfthread (not image handling specifically).  I would start there.

http://www.coldfusionjedi.com/index.cfm/2009/6/17/CFThread-Example--Creating-and-merging-PDFs

http://www.bennadel.com/blog/743-Learning-ColdFusion-8-CFThread-Part-I-Data-Exchange.htm

http://www.petefreitag.com/item/650.cfm

Message was edited by: -==cfSearching==-