Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Greyscaling and resizing images not working?

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 4124 Views
  • blueskies
    Avatar
    Community Member
    42 Posts

    Greyscaling and resizing images not working? Link to this post

    For some reason I can't get the greyscale to work with a resize:

    function generateLogoH30Grey($gd) {
       $gd->setQuality(100);
       $gd->paddedResize(70,30);
       return $gd->greyscale();
    }


    The above example gives me back grey images, but they are the original size (so paddedresize is cancelled) rather than width 70 and height 30.

    function generateLogoH30Grey($gd) {
       $gd->setQuality(100);
       $gd->greyscale();
       return $gd->paddedResize(70,30);
    }


    And the above gives me resized images as expected but then the greyscale is cancelled (so the images are back in color).

    Does anybody have any experience with resize/greyscale combinations? What am I overlooking?

    I looked at the code in the gd class, and it would seem that it should work either way....?

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Greyscaling and resizing images not working? Link to this post

    I think your problem may be that your changes are not carried over to the next line of code - each of these methods return a new instance of the GD class rather than modifying the existing one. Have you tried chaining your methods together?

    public function generateLogoH30Grey($gd) {
       return $gd->setQuality(100)->paddedResize(70, 30)->greyscale();
    }

  • blueskies
    Avatar
    Community Member
    42 Posts

    Re: Greyscaling and resizing images not working? Link to this post

    Thanks for your reply, ajshort!

    That is a very good point, and when I read your post I thought, "Duh! That's it!". But unfortunately I'm getting even bigger problems when chaining:
    Fatal error: Call to a member function paddedResize() on a non-object

    So, that's not the solution, or the syntax of the chaining is incorrect.

    By the way, the one $gd per line style is according to the docs: http://doc.silverstripe.com/doku.php?id=imageupload (under the 'More advanced uses' heading, there's an example).

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Greyscaling and resizing images not working? Link to this post

    I had a quick look at the GD class - some functions do create a new instance, others don't. Maybe try:

    public function generateLogoH30Grey(GD $gd) {
       $gd = $gd->PaddedResize(70, 30)->greyscale();
       $gd->setQuality(100);
       
       return $gd;
    }

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