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.

Archive

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

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

Greyscaling and resizing images not working?


Reply

4 Posts   4199 Views

Avatar
blueskies

15 December 2008 at 10:43pm (Last edited: 15 December 2008 10:43pm), Community Member, 42 Posts

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

Avatar
ajshort

15 December 2008 at 11:05pm Community Member, 244 Posts

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

Avatar
blueskies

15 December 2008 at 11:17pm Community Member, 42 Posts

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

Avatar
ajshort

15 December 2008 at 11:34pm Community Member, 244 Posts

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