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|null $assetContainer = null)

Create a new backend with the given object

public
string|null
getTempPath()

Get the temporary local path for this image

public
setTempPath(string $path)

Set the temporary local path for this image

public
CacheInterface
getCache()

No description

public
setCache(CacheInterface $cache)

No description

public
AssetContainer|null
getAssetContainer()

No description

public
setAssetContainer(AssetContainer|null $assetContainer)

No description

public
ImageManager
getImageManager()

No description

public
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(ImageInterface $image)

No description

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

No description

public
bool
writeTo(string $path)

No description

public
int
getQuality()

No description

protected
array
getDimensions()

Return dimensions as array with cache enabled

protected
array
getResourceDimensions(ImageInterface $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
void
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)

No description

public
resize(int $width, int $height)

No description

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

No description

public
resizeByWidth(int $width)

No description

public
resizeByHeight(int $height)

No description

public
paddedResize(string $width, string $height, string $backgroundColour = 'FFFFFF', int $transparencyPercent = 0)

No description

public
croppedResize(int $width, int $height, string $position = 'center')

No description

public
crop(int $top, int $left, int $width, int $height, string $position = 'top-left', string $backgroundColour = 'FFFFFF')

No description

public
setAllowsAnimationInManipulations(bool $allow)

No description

public
bool
public
bool
getIsAnimated()

No description

public
removeAnimation(int|string $position)

No description

protected
createCloneWithResource(ImageInterface|callable $resourceOrTransformation)

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

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

Clear any cached errors / metadata for this image

protected
void
markFailed(string $hash, string|null $variant = null, string $reason = InterventionBackend::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|null $assetContainer = null)

Create a new backend with the given object

Parameters

AssetContainer|null $assetContainer

Object to load from

string|null getTempPath()

Get the temporary local path for this image

Return Value

string|null

InterventionBackend setTempPath(string $path)

Set the temporary local path for this image

Parameters

string $path

Return Value

InterventionBackend

CacheInterface getCache()

No description

Return Value

CacheInterface

InterventionBackend setCache(CacheInterface $cache)

No description

Parameters

CacheInterface $cache

Return Value

InterventionBackend

AssetContainer|null getAssetContainer()

No description

Return Value

AssetContainer|null

InterventionBackend setAssetContainer(AssetContainer|null $assetContainer)

No description

Parameters

AssetContainer|null $assetContainer

Return Value

InterventionBackend

ImageManager getImageManager()

No description

Return Value

ImageManager

InterventionBackend setImageManager(ImageManager $manager)

No description

Parameters

ImageManager $manager

Return Value

InterventionBackend

Image_Backend loadFromContainer(AssetContainer $assetContainer)

Populate the backend with a given object

Parameters

AssetContainer $assetContainer

Object to load from

Return Value

Image_Backend

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

Image_Backend loadFrom(string $path)

Populate the backend from a local path

Parameters

string $path

Return Value

Image_Backend

Image_Backend setImageResource(ImageInterface $image)

No description

Parameters

ImageInterface $image

Return Value

Image_Backend

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

No description

Parameters

AssetStore $assetStore
string $filename

Name for the resulting file

string|null $hash

Hash of original file, if storing a variant.

string|null $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)

No description

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

Returns a two-length array with width and height

Return Value

array

protected array getResourceDimensions(ImageInterface $resource)

Get dimensions from the given resource

Parameters

ImageInterface $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 void warmCache(string $hash, string|null $variant = null)

Warm dimension cache for the given asset

Parameters

string $hash
string|null $variant

Return Value

void

int getWidth()

No description

Return Value

int

int getHeight()

No description

Return Value

int

Image_Backend setQuality(int $quality)

No description

Parameters

int $quality

Return Value

Image_Backend

Image_Backend|null resize(int $width, int $height)

No description

Parameters

int $width
int $height

Return Value

Image_Backend|null

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

No description

Parameters

int $width
int $height
bool $useAsMinimum

Return Value

Image_Backend|null

Image_Backend|null resizeByWidth(int $width)

No description

Parameters

int $width

Return Value

Image_Backend|null

Image_Backend|null resizeByHeight(int $height)

No description

Parameters

int $height

Return Value

Image_Backend|null

Image_Backend|null paddedResize(string $width, string $height, string $backgroundColour = 'FFFFFF', int $transparencyPercent = 0)

No description

Parameters

string $width
string $height
string $backgroundColour
int $transparencyPercent

Return Value

Image_Backend|null

Image_Backend|null croppedResize(int $width, int $height, string $position = 'center')

No description

Parameters

int $width
int $height
string $position

Return Value

Image_Backend|null

Image_Backend|null crop(int $top, int $left, int $width, int $height, string $position = 'top-left', string $backgroundColour = 'FFFFFF')

No description

Parameters

int $top

Amount of pixels the cutout will be moved on the y (vertical) axis

int $left

Amount of pixels the cutout will be moved on the x (horizontal) axis

int $width

rectangle width

int $height

rectangle height

string $position

Postion at which the cutout will be aligned

string $backgroundColour

Colour to fill any newly created areas

Return Value

Image_Backend|null

Image_Backend setAllowsAnimationInManipulations(bool $allow)

No description

Parameters

bool $allow

Return Value

Image_Backend

bool getAllowsAnimationInManipulations()

No description

Return Value

bool

bool getIsAnimated()

No description

Return Value

bool

Image_Backend|null removeAnimation(int|string $position)

No description

Parameters

int|string $position

Which frame to use as the still image. If an integer is passed, it represents the exact frame number to use (starting at 0). If that frame doesn't exist, an exception is thrown. If a string is passed, it must be in the form of a percentage (e.g. '0%' or '50%'). The frame to use is then determined based on this percentage (e.g. if '50%' is passed, a frame halfway through the animation is used).

Return Value

Image_Backend|null

protected InterventionBackend|null createCloneWithResource(ImageInterface|callable $resourceOrTransformation)

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

Parameters

ImageInterface|callable $resourceOrTransformation

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

Return Value

InterventionBackend|null

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

Clear any cached errors / metadata for this image

Parameters

string $hash
string|null $variant

Return Value

void

protected void markFailed(string $hash, string|null $variant = null, string $reason = InterventionBackend::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

Return Value

void

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