imageurlcoldfusionhrefcfimage

Is it possible to retrieve the path of a Coldfusion image tag to directly link to the picture?


I'm trying to use Coldfusions CFimage tag and Photoswipe.

My problem is, Photoswipe requires images to be set up like this:

<a class="swipeMe" rel="external" href="#myImage#">
   <cfimage source="#myImage#" action="writeToBrowser" class="adaptImg ui-li-thumb">
</a>

So I need the url for the link href and cfimage tag.

If I parse this, the img source will be

src="/CFFileServlet/_cf_image/_cfimg5722874764512027443.PNG"

while the link href turns out to be:

href="coldfusion.image.Image@1adaa15"

Which breaks the photoswipe plugin, because the image can't be found.

Question:
Is there a way in Coldfusion8 to display the actual image path in the href, so the image can be linked to?

Thanks for help!


Solution

  • You can use regex to parse out the URL, or use <cfxml> like Ben Nadel did:

    <!---
        Write the image to the output. Except, rather than writing it
        to the screen, write it to an XML data buffer.
    --->
    <cfxml variable="imageXml">
    
    <!--- Let IMG be the only tag in this XML document. --->
    <cfimage
        action="writetobrowser"
        source="#girlsFighting#"/>
    
    </cfxml>
    
    
    <!---
        At this point, our XML object should have one tag - IMG - from
       which we can extract the SRC attribute as the temporary image
        path on the CFImage file servlet.
    --->
    <cfset imageSrc = imageXml.xmlRoot.xmlAttributes.src />
    
    
    <!--- Output the temporary image src: --->
    <cfoutput>
        SRC: #imageSrc#
    </cfoutput>