1

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!

frequent
  • 27,643
  • 59
  • 181
  • 333

1 Answers1

3

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>
Henry
  • 32,689
  • 19
  • 120
  • 221
  • hey. just stumbled across Ben Nadel cfxml, too. Do you know what happens to the XML buffer after I display the image. Do I need to delete/remove it? – frequent Jul 11 '12 at 19:14
  • you mean the `imageXml` variable? Well just make sure you're doing proper var-scooping if it's in a function, and you'll be fine. – Henry Jul 11 '12 at 19:29
  • Ok.Thanks. This works nicely! So I have to use variables.imageSrc instead of imageSrc? I'm using it in a loop, so it gets overwritten with every iteration anyway. – frequent Jul 11 '12 at 19:44