Well, I myself went, and this is what I came up with:
_config.php
Object::add_extension('Image', 'Greyscaled');
UPDATE: as of SilverStripe 3.1, you should use the configuration system instead of _config.php . Put the mysite/_config/config.yml in mysite/_config/config.yml (do not forget ?flush=1 reload the configuration cache after adding):
Image: extensions: - 'Greyscaled'
Greyscaled.php
<?php class Greyscaled extends DataExtension {
UPDATE2: With newer versions 3.1? you can pass more than two parameters, and GD has been renamed Image_Backend. This way you have no spaces between the RGB values ββin the image name. Be aware that $ gd-> greyscale needs a lot of juice, so you can reduce the size and GreyscaleImage first.
UPDATE3:. Since this answer received several votes, I assume that people are still using it, but I think that in 2017 CSS filters are in many cases the best choice. With the prefix, you will have about 90% coverage. css filters on caniuse.com
<?php class Greyscaled extends DataExtension { public function GreyscaleImage($R = '76', $G = '147', $B = '29') { return $this->owner->getFormattedImage('GreyscaleImage', $R, $G, $B); } public function generateGreyscaleImage(Image_Backend $gd, $R, $G, $B) { return $gd->greyscale($R, $G, $B); } }
and in the template:
<img src="$Images.GreyscaleImage.CroppedImage(1000,400).URL" alt="$Images.Title" />
Silverstripe 3.1 Image API