Jump to:

23456 Posts in 18905 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Extending Image

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

Page: 1
Go to End
Author Topic: 1452 Views
  • Bambii7
    Avatar
    Community Member
    254 Posts

    Extending Image Link to this post

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

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Extending Image Link to this post

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

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: Extending Image Link to this post

    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.

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: Extending Image Link to this post

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

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: Extending Image Link to this post

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

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: Extending Image Link to this post

    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.

    1452 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.