Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » linking to resized images....

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

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

Page: 1
Go to End
Author Topic: 1515 Views
  • Nicolaas
    Avatar
    Forum Moderator
    213 Posts

    linking to resized images.... Link to this post

    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

  • Nicolaas
    Avatar
    Forum Moderator
    213 Posts

    Re: linking to resized images.... Link to this post

    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

    1515 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.