class InterventionBackend implements Image_Backend, Flushable (View source)

Traits

Provides extensions to this object to integrate it with standard config API methods.

Constants

CACHE_MARK

Cache prefix for marking

CACHE_DIMENSIONS

Cache prefix for dimensions

FAILED_INVALID

This file is invalid because it is not image data, or it cannot be processed by the given backend

FAILED_MISSING

This file is invalid as it is missing from the filesystem

FAILED_UNKNOWN

Some unknown error

Config options

flush_enabled bool

Is cache flushing enabled?

error_cache_ttl array

How long to cache each error type

local_temp_path string

Configure where cached intervention files will be stored

Properties

Methods

public static 
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

public
__construct(AssetContainer $assetContainer = null)

Create a new backend with the given object

public
string
getTempPath()

No description

public
$this
setTempPath(string $path)

No description

public
CacheInterface
getCache()

No description

public
$this
setCache(CacheInterface $cache)

No description

public
getAssetContainer()

No description

public
$this
setAssetContainer(AssetContainer $assetContainer)

No description

public
ImageManager
getImageManager()

No description

public
$this
setImageManager(ImageManager $manager)

No description

public
loadFromContainer(AssetContainer $assetContainer)

Populate the backend with a given object

public
mixed
getImageResource()

Get the currently assigned image resource, or generates one if not yet assigned.

public
loadFrom(string $path)

Populate the backend from a local path

public
setImageResource(Image $image)

No description

public
array
writeToStore(AssetStore $assetStore, string $filename, string $hash = null, string $variant = null, array $config = [])

Write to the given asset store

public
bool
writeTo(string $path)

Write the backend to a local path

public
int
getQuality()

No description

protected
array
getDimensions()

Return dimensions as array with cache enabled

protected
array
getResourceDimensions(Image $resource)

Get dimensions from the given resource

protected
string
getErrorCacheKey(string $hash, string|null $variant = null)

Cache key for recording errors

protected
string
getDimensionCacheKey(string $hash, string|null $variant = null)

Cache key for dimensions for given container

protected
warmCache(string $hash, string|null $variant = null)

Warm dimension cache for the given asset

public
int
getWidth()

No description

public
int
getHeight()

No description

public
setQuality(int $quality)

Set the quality to a value between 0 and 100

public
resize(int $width, int $height)

Resize an image, skewing it as necessary.

public
resizeRatio(int $width, int $height, bool $useAsMinimum = false)

Resize the image by preserving aspect ratio. By default, it will keep the image inside the maxWidth and maxHeight. Passing useAsMinimum will make the smaller dimension equal to the maximum corresponding dimension

public
resizeByWidth(int $width)

Resize an image by width. Preserves aspect ratio.

public
resizeByHeight(int $height)

Resize an image by height. Preserves aspect ratio.

public
paddedResize(int $width, int $height, string $backgroundColor = "FFFFFF", int $transparencyPercent = 0)

Return a clone of this image resized, with space filled in with the given colour

public
croppedResize(int $width, int $height)

Resize an image to cover the given width/height completely, and crop off any overhanging edges.

public
crop(int $top, int $left, int $width, int $height)

Crop's part of image.

protected
createCloneWithResource(Image|callable $resourceOrTransformation)

Modify this image backend with either a provided resource, or transformation

protected
markSuccess(string $hash, string|null $variant = null)

Clear any cached errors / metadata for this image

protected
markFailed(string $hash, string|null $variant = null, string $reason = self::FAILED_UNKNOWN)

Mark this image as failed to load

protected
string|null
hasFailed(string $hash, string|null $variant = null)

Determine reason this file could not be loaded.

public
__destruct()

Make sure we clean up the image resource when this object is destroyed

public static 
flush()

This function is triggered early in the request if the "flush" query parameter has been set. Each class that implements Flushable implements this function which looks after it's own specific flushing functionality.

protected
bool
isStreamReadable(mixed $stream)

Validate the stream resource is readable

Details

static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

Return Value

Config_ForClass

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

__construct(AssetContainer $assetContainer = null)

Create a new backend with the given object

Parameters

AssetContainer $assetContainer

Object to load from

string getTempPath()

No description

Return Value

string

The temporary local path for this image

$this setTempPath(string $path)

No description

Parameters

string $path

Return Value

$this

CacheInterface getCache()

No description

Return Value

CacheInterface

$this setCache(CacheInterface $cache)

No description

Parameters

CacheInterface $cache

Return Value

$this

AssetContainer getAssetContainer()

No description

Return Value

AssetContainer

$this setAssetContainer(AssetContainer $assetContainer)

No description

Parameters

AssetContainer $assetContainer

Return Value

$this

ImageManager getImageManager()

No description

Return Value

ImageManager

$this setImageManager(ImageManager $manager)

No description

Parameters

ImageManager $manager

Return Value

$this

loadFromContainer(AssetContainer $assetContainer)

Populate the backend with a given object

Parameters

AssetContainer $assetContainer

Object to load from

mixed getImageResource()

Get the currently assigned image resource, or generates one if not yet assigned.

Note: This method may return null if error

Return Value

mixed

loadFrom(string $path)

Populate the backend from a local path

Parameters

string $path

setImageResource(Image $image)

No description

Parameters

Image $image

array writeToStore(AssetStore $assetStore, string $filename, string $hash = null, string $variant = null, array $config = [])

Write to the given asset store

Parameters

AssetStore $assetStore
string $filename

Name for the resulting file

string $hash

Hash of original file, if storing a variant.

string $variant

Name of variant, if storing a variant.

array $config

Write options. {\SilverStripe\Assets\Storage\AssetStore}

Return Value

array

Tuple associative array (Filename, Hash, Variant) Unless storing a variant, the hash will be calculated from the given data.

Exceptions

BadMethodCallException

bool writeTo(string $path)

Write the backend to a local path

Parameters

string $path

Return Value

bool

if the write was successful

Exceptions

BadMethodCallException

int getQuality()

No description

Return Value

int

protected array getDimensions()

Return dimensions as array with cache enabled

Return Value

array

Two-length array with width and height

protected array getResourceDimensions(Image $resource)

Get dimensions from the given resource

Parameters

Image $resource

Return Value

array

protected string getErrorCacheKey(string $hash, string|null $variant = null)

Cache key for recording errors

Parameters

string $hash
string|null $variant

Return Value

string

protected string getDimensionCacheKey(string $hash, string|null $variant = null)

Cache key for dimensions for given container

Parameters

string $hash
string|null $variant

Return Value

string

protected warmCache(string $hash, string|null $variant = null)

Warm dimension cache for the given asset

Parameters

string $hash
string|null $variant

int getWidth()

No description

Return Value

int

The width of the image

int getHeight()

No description

Return Value

int

The height of the image

setQuality(int $quality)

Set the quality to a value between 0 and 100

Parameters

int $quality

Image_Backend resize(int $width, int $height)

Resize an image, skewing it as necessary.

Parameters

int $width
int $height

Return Value

Image_Backend

Image_Backend resizeRatio(int $width, int $height, bool $useAsMinimum = false)

Resize the image by preserving aspect ratio. By default, it will keep the image inside the maxWidth and maxHeight. Passing useAsMinimum will make the smaller dimension equal to the maximum corresponding dimension

Parameters

int $width
int $height
bool $useAsMinimum

If true, image will be sized outside of these dimensions. If false (default) image will be sized inside these dimensions.

Return Value

Image_Backend

Image_Backend resizeByWidth(int $width)

Resize an image by width. Preserves aspect ratio.

Parameters

int $width

Return Value

Image_Backend

Image_Backend resizeByHeight(int $height)

Resize an image by height. Preserves aspect ratio.

Parameters

int $height

Return Value

Image_Backend

Image_Backend paddedResize(int $width, int $height, string $backgroundColor = "FFFFFF", int $transparencyPercent = 0)

Return a clone of this image resized, with space filled in with the given colour

Parameters

int $width
int $height
string $backgroundColor
int $transparencyPercent

Return Value

Image_Backend

Image_Backend croppedResize(int $width, int $height)

Resize an image to cover the given width/height completely, and crop off any overhanging edges.

Parameters

int $width
int $height

Return Value

Image_Backend

Image_Backend crop(int $top, int $left, int $width, int $height)

Crop's part of image.

Parameters

int $top

y position of left upper corner of crop rectangle

int $left

x position of left upper corner of crop rectangle

int $width

rectangle width

int $height

rectangle height

Return Value

Image_Backend

protected InterventionBackend createCloneWithResource(Image|callable $resourceOrTransformation)

Modify this image backend with either a provided resource, or transformation

Parameters

Image|callable $resourceOrTransformation

Either the resource to assign to the clone, or a function which takes the current resource as a parameter

Return Value

InterventionBackend

protected markSuccess(string $hash, string|null $variant = null)

Clear any cached errors / metadata for this image

Parameters

string $hash
string|null $variant

protected markFailed(string $hash, string|null $variant = null, string $reason = self::FAILED_UNKNOWN)

Mark this image as failed to load

Parameters

string $hash

Hash of original file being manipluated

string|null $variant

Variant being loaded

string $reason

Reason this file is failed

protected string|null hasFailed(string $hash, string|null $variant = null)

Determine reason this file could not be loaded.

Will return one of the FAILED_* constant values, or null if not failed

Parameters

string $hash

Hash of the original file being manipulated

string|null $variant

Return Value

string|null

__destruct()

Make sure we clean up the image resource when this object is destroyed

static flush()

This function is triggered early in the request if the "flush" query parameter has been set. Each class that implements Flushable implements this function which looks after it's own specific flushing functionality.

See also

FlushRequestFilter

protected bool isStreamReadable(mixed $stream)

Validate the stream resource is readable

Parameters

mixed $stream

Return Value

bool