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.

Template Questions /

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

Image Resize Question


Go to End


2 Posts   2387 Views

Avatar
bmc38119

Community Member, 45 Posts

17 March 2009 at 7:43am

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.

Avatar
bmc38119

Community Member, 45 Posts

17 March 2009 at 4:40pm

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.