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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Greyscaling and resizing images not working?


Go to End


4 Posts   5510 Views

Avatar
blueskies

Community Member, 44 Posts

15 December 2008 at 10:43pm

Edited: 15/12/2008 10:43pm

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

Community Member, 244 Posts

15 December 2008 at 11:05pm

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

Community Member, 44 Posts

15 December 2008 at 11:17pm

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

Community Member, 244 Posts

15 December 2008 at 11:34pm

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