interface Image_Backend (View source)

Image_Backend

A backend for manipulation of images via the Image class

Constants

ORIENTATION_SQUARE

Represents a square orientation

ORIENTATION_PORTRAIT

Represents a portrait orientation

ORIENTATION_LANDSCAPE

Represents a landscape orientation

Methods

public
__construct(AssetContainer|null $assetContainer = null)

Create a new backend with the given object

public
int
getWidth()

Get the width of the image

public
int
getHeight()

Get the height of the image

public
loadFromContainer(AssetContainer $assetContainer)

Populate the backend with a given object

public
loadFrom(string $path)

Populate the backend from a local path

public
mixed
getImageResource()

Get the currently assigned image resource

public
setImageResource($resource)

Set the currently assigned image resource

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

Write to the given asset store

public
bool
writeTo(string $path)

Write the backend to a local path

public
setQuality(int $quality)

Set the quality to a value between 0 and 100

public
int
getQuality()

Get the current quality (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, the image cannot be resized to be larger than its current size.

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(string $width, string $height, string $backgroundColour = '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, string $position = 'center')

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, string $position, string $backgroundColour = 'FFFFFF')

Crop's part of image.

public
setAllowsAnimationInManipulations(bool $allow)

Set whether this image backend is allowed to output animated images as a result of manipulations.

public
bool
getAllowsAnimationInManipulations()

Get whether this image backend is allowed to output animated images as a result of manipulations.

public
bool
getIsAnimated()

Check if the image is animated (e.g. an animated GIF).

public
removeAnimation(int|string $position)

Discards all animation frames of the current image instance except the one at the given position. Turns an animated image into a static one.

Details

__construct(AssetContainer|null $assetContainer = null)

Create a new backend with the given object

Parameters

AssetContainer|null $assetContainer

Object to load from

int getWidth()

Get the width of the image

Return Value

int

int getHeight()

Get the height of the image

Return Value

int

Image_Backend loadFromContainer(AssetContainer $assetContainer)

Populate the backend with a given object

Parameters

AssetContainer $assetContainer

Object to load from

Return Value

Image_Backend

Image_Backend loadFrom(string $path)

Populate the backend from a local path

Parameters

string $path

Return Value

Image_Backend

mixed getImageResource()

Get the currently assigned image resource

Return Value

mixed

Image_Backend setImageResource($resource)

Set the currently assigned image resource

Parameters

$resource

Return Value

Image_Backend

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

Write to the given asset store

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.

bool writeTo(string $path)

Write the backend to a local path

Parameters

string $path

Return Value

bool

if the write was successful

Image_Backend setQuality(int $quality)

Set the quality to a value between 0 and 100

Parameters

int $quality

Return Value

Image_Backend

int getQuality()

Get the current quality (between 0 and 100).

Return Value

int

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

Resize an image, skewing it as necessary.

Parameters

int $width
int $height

Return Value

Image_Backend|null

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

Resize the image by preserving aspect ratio. By default, the image cannot be resized to be larger than its current size.

Passing true to useAsMinimum will allow the image to be scaled up.

Parameters

int $width
int $height
bool $useAsMinimum

Return Value

Image_Backend|null

Image_Backend|null resizeByWidth(int $width)

Resize an image by width. Preserves aspect ratio.

Parameters

int $width

Return Value

Image_Backend|null

Image_Backend|null resizeByHeight(int $height)

Resize an image by height. Preserves aspect ratio.

Parameters

int $height

Return Value

Image_Backend|null

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

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

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')

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

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, string $backgroundColour = 'FFFFFF')

Crop's part of image.

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)

Set whether this image backend is allowed to output animated images as a result of manipulations.

Parameters

bool $allow

Return Value

Image_Backend

bool getAllowsAnimationInManipulations()

Get whether this image backend is allowed to output animated images as a result of manipulations.

Return Value

bool

bool getIsAnimated()

Check if the image is animated (e.g. an animated GIF).

Will return false if animations are not allowed for manipulations.

Return Value

bool

Image_Backend|null removeAnimation(int|string $position)

Discards all animation frames of the current image instance except the one at the given position. Turns an animated image into a static one.

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