heyday/silverstripe-imageextension

There is no license information available for the latest version (1.0.0) of this package.

Provides the ability to extend images in SilverStripe

This package's canonical repository appears to be gone and the package has been frozen as a result.

Installs: 5 795

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 28

Forks: 2

Open Issues: 0

Type:silverstripe-module

1.0.0 2013-07-14 02:15 UTC

This package is auto-updated.

Last update: 2024-04-29 02:35:08 UTC


README

Provides the ability to extend images in SilverStripe

The problem

Providing custom image formatting was in the past thought to be easy. We would just extend Image and add our generateX functions there. We found over time however that this caused some major issues for clients, issues where images associated with certain pages, both added through Content and also associated via has_X would suddenly disappear. The underlying reason for this was a change of ClassName in the database record when the same image would be used somewhere else in the CMS (for example usage in TinyMce).

Our next option was to create a DataObjectDecorator or DataExtension and add the generateX methods there, but this had a annoyance of its own.

To achieve this you had to do something like the following:

class CustomImage extends DataExtension
{
    public function MyCustomFormat()
    {
        return $this->owner->getFormattedImage('MyCustomFormat');
    }

    public function generateMyCustomFormat(Image_Backend $backend)
    {
        return $backend->fittedResize(80, 110);
    }
}

Notice the need to define MyCustomFormat as well as generateMyCustomFormat. This gets kinda ugly when you have many formatting functions. Not nice.

The solution

To avoid this, you can now use heyday/silverstripe-imageextension. Which will allow you to simply define the generateX methods in your extension.

Installation (with composer)

$ composer require heyday/silverstripe-imageextension

Usage

class CustomImageExtension extends \Heyday\SilverStripe\ImageExtension
{
    public function generateTwoColumn(Image_Backend $backend)
    {
        $backend->resizeByWidth(300);
        return $backend;
    }
}

mysite/_config/config.yml

Image:
    extensions:
        - CustomImageExtension

##License

SilverStripe Image Extension is licensed under an MIT license