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.

Themes /

Discuss SilverStripe Themes.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

lightbox: should I do this?


Reply


3 Posts   1953 Views

Avatar
yurigoul

Community Member, 202 Posts

29 October 2009 at 3:35am

Edited: 29/10/2009 3:39am

I ran accross a snippet at [url=http://www.ssbits.com/resizing-an-image-in-a-custom-img-tag/]ssbits[/url] and I extended the snippet to to create a lightbox enabled image link in my page.ss. I have not tested this with lightbox installed but I am pretty confident this would work for lightbox and with some adaptation this should work for any other lightbox-clone:

<% control MyImage %>
   <% control SetHeight(600) %>
      <a href="$URL" rel="lightbox">
   <% end_control %>

   <% control CroppedImage(580, 200) %>
      <img src="$URL" />
   <% end_control %>

   </a>
<% end_control %>

this results in:

<a href="/s/assets/Uploads/_resampled/SetHeight600-myimage.jpg" rel="lightbox">   
   <img src="/s/assets/Uploads/_resampled/croppedimage580200-myimage2.jpg" />
</a>

I have three questions:

  • Is there any reason why I should not do this? I know there is also the option of adding gd functions to the page.php, so is there any reason I should be using that instead?

  • The author gave these other possiblities for controling the image: CroppedImage(w,h), PaddedImage(w,h), ResizedImage(w,h), control SetWidth(w), control SetHeight(h). These should be documented in the gd api documentation, but I can not find them. Where can I find out about these methods, and are there more?

  • I noticed I can use $Title to get the name of the image, and in this way I would be able to use the name as a title and alt attribute. However I can only use it inside the first control statement (control MyImage). Are there any other variables like that, that I can use?

Avatar
Willr

Forum Moderator, 5513 Posts

29 October 2009 at 6:08pm

Is there any reason why I should not do this
No, if it works for you then roll with that.

Where can I find out about these methods, and are there more

Probably not a complete list but the bulk of methods are available at http://doc.silverstripe.org/doku.php?id=image

Are there any other variables like that, that I can use?

You can use any of the File, Image database fields or any of the methods defined in Image.php or File.php. To see whats available open up those files and see whats in the $db array.

Avatar
yurigoul

Community Member, 202 Posts

29 October 2009 at 9:09pm

Thanks for the answer, I will certainly look into the filephp and image.php. What confused me is that I thought things like direct image manipulation should take place in the page.php and with the page.ss you just retreive the data. I could also do this with the gd functions in the page.php - is one better than the other?

The link you gave me does not document methods like CroppedIMage. I was wondering if there was an equivalent to croppedResize etc.

I expanded the code to this, am just sharing it. MainImage is the image and MainImageTitle is a text field that holds the title etc.

<% if MainImage %>
   <% control MainImage %>
      <% control SetHeight(600) %>
         <a href="$URL" title="$Top.MainImageTitle" rel="lightbox">
      <% end_control %>
      <% control CroppedImage(580, 200) %>
         <img src="$URL" title="$Top.MainImageTitle" alt="$Top.MainImageTitle" />
      <% end_control %>
      </a>
   <% end_control %>
<% end_if %>