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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Extending Image to generate greyscale.


Go to End


622 Views

Avatar
dave.m

Community Member, 19 Posts

11 March 2015 at 2:01am

Edited: 11/03/2015 2:02am

On 3.1.10
I have an extension to Image to render images in greyscale.
First image in loop gets rendered to "_resampled" folder but no others, and the one that did get saved doesn't make it to the page.
Any ideas?

Extension looks like this

class Greyscale extends DataExtension {
    public function GreyscaleImage($RGB = '76 147 29') {
        return $this->owner->getFormattedImage('GreyscaleImage', $RGB);
    }

    public function generateGreyscaleImage(GD $gd, $RGB) {
        $Vars = explode(' ', $RGB);
        return $gd->greyscale($Vars[0], $Vars[1], $Vars[2]);
    }
}

Template - each Panel has an image property called Image.

<% loop Panels.Limit(3, 0) %>
            <div class="col-md-3 col-sm-6 hidden-xs nav_grid_top">
                <img src="$Image.GreyscaleImage.CroppedImage(475, 550).URL" alt="$Image.Title" class="nav_grid_img"/>
                <div class="nav_grid_content">
                    <h3>$Title</h3>
                    <hr/>
                    <h4>$SubTitle</h4>
                    <p>$Text</p>
                    <a href="$Link.Link">$ButtonText</a>
                </div>
            </div>
        <% end_loop %>

Thanks.