22849 Posts in 9710 Topics by 2803 members
|Go to End|
17 November 2011 at 1:46pm
I made a shortcode to embed images that I upload through the files and images tab. In my template, I would like to be able to resize this image but I can not really see how to do that. I've done it before using $SetWidth, ResizedImage, etc, with images in custom page types but it does not seem to work with the URL to the image I generate with my shortcode pardser. is that because it is an "image object" when it is a page type? I hope I am making sense here, I'm on the edge of my SilverStripe knowledge coding in the dark :0)
Basically I want to use a resize function on the source for an image tag, hopefully saving and caching the resized image like it seems to do in SS. How can I do that?
17 November 2011 at 2:28pm
You could try something like this - where SpecialImage returns an image object. From memory I think you can use for instance $SpecialImage.CroppedImage(200,100) to render the whole image tag, but <% control SpecialImage.CroppedImage(200,100) %> won't work, hence two control blocks.
<% if SpecialImage %>
<% control SpecialImage %>
<% control CroppedImage(200,100) %>
<img src="$Link" alt="" width="$Width" height="$Height" />
<% end_control %>
<% end_control %>
<% end_if %>
17 November 2011 at 4:37pm
Thank you for your reply!
But what is "SpecialImage"? Is that something particular to SS, or is that something I have to add to my page? I think that is my problem in that I am not dealing with an Image Object (at least I don't think I am), I just want to resize the image on a plain old image tag like:
<a class="rfb" href="./assets/Uploads/$directory/$imagename" title="$caption"><img alt="$caption" src="./assets/Uploads/$directory/$imagename->SetHeight(100);" /></a>
only that doesn't do anything
If I take out the resize I see the image just fine, so I know the shortcode and template is working, like this:
<a class="rfb" href="./assets/Uploads/$directory/$imagename" title="$caption"><img alt="$caption" src="./assets/Uploads/$directory/$imagename" /></a>
See what I mean? How would I resize a dynamically generated image tag that I am assuming is not an image object?
18 November 2011 at 6:30am
Does anyone have any idea on this? Is there a way with SS to resize an image on an image tag? The image is not an Image Object attached to the page it's just in a folder on my site and I am generating an image tag to put it on the page. I've seens some PHP scripts for creating thumbnails on the fly and caching them, I suppose I could work that in somehow, but I was wondering if there was a way to do it with SS.
18 November 2011 at 2:07pm
If you want to use SilverStripe's image functions you'll need to be working with an image object. So if you have some kind of shortcode function - rather than using it to return a string such as the directory name, make your function fetch the relevant image (i.e. using a DataObject::get) and return it to the template so you can access SilverStripe's built in image functions.
Also $imagename->SetHeight(100) wouldn't work in a template even if $imagename was an image object, the syntax would be $imagename.SetHeight(100)
|Go to Top|