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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

linking to resized images....


Go to End


2 Posts   1844 Views

Avatar
Nicolaas

Forum Moderator, 224 Posts

22 November 2007 at 11:45pm

Hi Folk

I have a page with an image. In the templates I can write

$Pic1.SetWidth(147), which creates the image at 147pixels wide
I can write <a href="$Pic1.URL">see picture</a>, which links through to the image. However, I am not sure how I can link through to a resized image. Is that possible? I want people to see the image at different sizes - something like

<a href="$Pic1.SetWidth(800).URL">open a 800x600 picture</a>

How do I do that and do I need to pre-create the images at the desired sizes?

Thank you

Nicolaas

Avatar
Nicolaas

Forum Moderator, 224 Posts

23 November 2007 at 9:40am

I have done this:

class DesktopItemsPage extends Page {
...
static $has_one = array(
'Pic1' => 'Image',
);
...
}

class DesktopItemsPage_Controller extends Page_Controller {

}

class Desktop_Image extends Image {
static $db = null;

function generateDesktopSmall($gd) {
$gd->setQuality(90);
return $gd->paddedResize(800,600);
}
function generateDesktopMedium($gd) {
$gd->setQuality(90);
return $gd->paddedResize(1024,768);
}
}

my template looks as follows (note that it uses child pages that each have a desktop stored in them as an image...). Thus, the actual page you are on is not a desktopItemsPage but a desktopPage.

<% control Children %>
<div class="desktop">
$Pic1.SetWidth(147)
<a href="$DesktopSmall.URL">800x600</a>
<a href="$DesktopMedium.URL">1024x768</a>
<a href="$Pic1.URL">1280x1024</a>
</div>
<% end_control %>

This does not seem to work (there are no links to small and medium image). Then I changed
'Pic1' => 'Image',
to
'Pic1' => 'Desktop_Image',
But that was even less successful - image was lost in its entirety.

Where am I going wrong?

Thank you

Nicolaas