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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Extending Image


6 Posts   1467 Views


2 September 2009 at 12:35pm (Last edited: 2 September 2009 12:38pm), Community Member, 254 Posts

Hey all, I've been going backwards and forwards through the wiki trying to find answers. Not sure if its me or Silver Stripe, so I ended up here.

Following this I've tired having this class in my dataobject, a gallery page, and finally thought it'd be best to have it self contained in its own file named "GalleryImage.php" with the following

class GalleryImage extends Image
   function generateLarge($gd) {
      return $gd->resizeRatio(350,500);

   function generateThumb($gd) {
      return $gd->paddedResize(100,100);


I always get call to member function on a non object. Am I naming the class incorectly? Some how the GD class isn't being accessed? Any light on the topic would be great. I'm using SS 2.3.3

I'm using uncle cheese's dataobject manager to allow for image caption and stuff, I'm associating the attachment with my GalleryImage like so

   static $has_one = array (
      'Attachment' => 'GalleryImage',
      'GalleryPage' => 'GalleryPage'


2 September 2009 at 7:09pm Community Member, 901 Posts

I have recently done something very similar to this and it worked just fine. How does your code in the template looks like?


3 September 2009 at 8:55am Community Member, 254 Posts

Thats good to hear that you've got it working, should hopefully mean I can to.
The code in the template is

      <img src="{$Attachment.Large.URL}" title="$Name" caption="$Caption"/>

I tried $Attachment.generateLarge.URL for the sake of it but get the same error.


3 September 2009 at 9:15am Community Member, 254 Posts

Pretty much all variations I try I end up with

Fatal error: Call to a member function setQuality() on a non-object in /home/lino/public_html/gallery/code/GalleryImage.php on line 5
with line 5 being       $gd->setQuality(100);


3 September 2009 at 10:51am Community Member, 254 Posts

Well I'm obviously missing something somewhere, I just installed the Image Gallery model and it works fine... I'll keep reading and trying.


3 September 2009 at 11:14am Community Member, 254 Posts

Well I've got it working. Not by extending the Image class but by writing functions in my DataObject. It might just be me but I found the wiki a little misleading.
Where is said croppedResize(width,height) it actually wanted CroppedImage(width,height). Do you have to write it Cropped{class name}(width, height); ??
Any way its bloody brilliant.