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


Reply


6 Posts   1515 Views

Avatar
Bambii7

Community Member, 254 Posts

2 September 2009 at 12:35pm

Edited: 02/09/2009 12:38pm

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 http://doc.silverstripe.com/doku.php?id=recipes:imageupload 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) {
      $gd->setQuality(100);
      return $gd->resizeRatio(350,500);
   }

   function generateThumb($gd) {
      $gd->setQuality(100);
      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

P.S
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'
   );
   

Avatar
banal

Community Member, 901 Posts

2 September 2009 at 7:09pm

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

Avatar
Bambii7

Community Member, 254 Posts

3 September 2009 at 8:55am

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.

Avatar
Bambii7

Community Member, 254 Posts

3 September 2009 at 9:15am

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);

Avatar
Bambii7

Community Member, 254 Posts

3 September 2009 at 10:51am

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

Avatar
Bambii7

Community Member, 254 Posts

3 September 2009 at 11:14am

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.