Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions

Getting the URL of a resized image


5 Posts   650 Views

Lime Blast

23 May 2013 at 2:13am Community Member, 22 Posts

I'm trying to build a custom function which returns the URL of a resized image..

The deal is that I'm going to have a series of thumbnail images listed on the page, each of which will link to a larger version of the image. I don't want the linked to image to be the full size image, however, as this is likely to be too large, so I wanted to provide a link to a resized image.

(Following me so far?)

Right now the code in my template looks like this:

<% if $Photos %>
   <ul class="project-photos">
      <% loop $Photos %>
         <li><a href="{$URL}">{$CroppedImage(210,210)}</a></li>
      <% end_loop %>
<% end_if %>

what I was planning on changing the `{$URL}` to something like `{$croppedURL(610)}`, and having a function on my Photo class (which extends the Image class) which returned the resized the URL, figuring I would do something like this:

public function croppedURL($width = false) {
   if ($width != false) {
   return $this->URL();

But upon doing so, I get a Server Error 500.

I'vee tried my best to make this work following the examples found on - but thus far I've not had any luck - can someone help please?

Thank you :)

Lime Blast

23 May 2013 at 2:18am Community Member, 22 Posts

As seems to be the story of my life right now - but no sooner than I finish posting this request for help, I find the answer.

Having looked at I've found that the solution to my problem already exists, I simply need to replace the `{$URL}` with `{$SetWidth(630).URL}` and it does exactly what I need it to do..

.. so that's great, but returning to my original question, just for my own knowledge, can anyone tell me why my attempted solution didn't work?


27 May 2013 at 11:46pm Community Member, 215 Posts

can anyone tell me why my attempted solution didn't work?

There is no method URL() in the Photo, Image or File class.

It would had worked if you used $this->getURL() or $this->URL.


29 May 2013 at 3:30pm Community Member, 254 Posts

I use this

$Image.SetSize( 75, 75 ).getAbsoluteURL

Lime Blast

29 May 2013 at 8:11pm Community Member, 22 Posts

@Bambii7 - is that the code for the class file?