Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » Image Resize Question

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

Page: 1
Go to End
Author Topic: 1356 Views
  • bmc38119
    Community Member
    45 Posts

    Image Resize Question Link to this post

    I have read the tutorial for creating a function to resize an image but i cannot seem to get it to work correctly. Here is my scenario:

    GalleryItemHolder.ss - this is the main Holder template that will contain the resized thumbnails
    GalleryItemPage.ss - this is the detail page for each of the GalleryItems - the images that are resized on the Holder page are attached so the GalleryItemPage class

    I have added the following code to the GalleryItemPage.php

    class GalleryItemPage extends Page {
    static $db = array(
    static $has_one = array(
    'GalleryItemImage' => 'Image',
        'GalleryItemThumb' => 'GalleryItemPage_Thumb150px'

    on what page do i put the following function class?

    class GalleryItemPage_Thumb150px extends Image {

    function generateThumb150px($gd) {
    return $gd->resizeRatio(150,150);

    If I put in the GalleryItemPage.php file, it does not seem to be callable in the GalleryItemHolder.ss template - which is where i want the resized thumbnails to be generated.

  • bmc38119
    Community Member
    45 Posts

    Re: Image Resize Question Link to this post

    I found the issue. I did not pick up on the fact that I needed to update the ClassName for all the existing images I had already uploaded in File table. Once I updated all the thumb images with the class name of GalleryItemPage_Thumb150px, the resize code worked. This is key for making this change after you've already uploaded images under the Image classname.

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.