ImageTransforms
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\ImageTransforms
- Since
- 4.0.0
Image Transforms helper.
View source (opens new window)
# Public Methods
Method | Description |
---|---|
createTransformFromString() | Create an AssetImageTransform model from a string. |
detectTransformFormat() | Detect the auto web-safe format for the Asset. Returns null, if the Asset is not an image. |
extendTransform() | Extend a transform by taking an existing transform and overriding its parameters. |
generateTransform() | Generates an image transform for an asset. |
getLocalImageSource() | Get a local image source to use for transforms. |
getTransformString() | Get the transform string for a given asset image transform. |
normalizeTransform() | Normalize a transform from handle or a set of properties to an ImageTransform. |
parseTransformString() | Parses a transform string. |
storeLocalSource() | Store a local image copy to a destination path. |
# createTransformFromString()
Create an AssetImageTransform model from a string.
View source (opens new window)
Arguments
$transformString
(string (opens new window))
Returns
# detectTransformFormat()
Detect the auto web-safe format for the Asset. Returns null, if the Asset is not an image.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)
Returns
Throws
- craft\errors\AssetOperationException
If attempting to detect an image format for a non-image.
# extendTransform()
Extend a transform by taking an existing transform and overriding its parameters.
View source (opens new window)
Arguments
$transform
(craft\models\ImageTransform)$parameters
(array (opens new window))
Returns
# generateTransform()
Generates an image transform for an asset.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset) – The asset$transform
(craft\models\ImageTransform) – The image transform$heartbeat
(callable (opens new window), null (opens new window)) – A callback that should be called while the transform is being generated$image
(craft\base\Image, null (opens new window)) – The image object loaded for the transform
Returns
string (opens new window) – The temp path that the transform was saved to
Throws
- craft\errors\ImageTransformException
if the transform couldn’t be generated.
# getLocalImageSource()
Get a local image source to use for transforms.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)
Returns
Throws
- craft\errors\FsObjectNotFoundException
If the file cannot be found.
# getTransformString()
Get the transform string for a given asset image transform.
View source (opens new window)
Arguments
$transform
(craft\models\ImageTransform)$ignoreHandle
(boolean (opens new window)) – Whether the transform handle should be ignored
Returns
# normalizeTransform()
Normalize a transform from handle or a set of properties to an ImageTransform.
View source (opens new window)
Arguments
$transform
(mixed
)
Returns
craft\models\ImageTransform, null (opens new window)
Throws
- craft\errors\ImageTransformException
if $transform is an invalid transform handle
# parseTransformString()
- Since
- 4.4.0
Parses a transform string.
View source (opens new window)
Arguments
$str
(string (opens new window))
Returns
# storeLocalSource()
Store a local image copy to a destination path.
View source (opens new window)
Arguments
$source
(string (opens new window))$destination
(string (opens new window))
Throws
# Constants
Constant | Description |
---|---|
TRANSFORM_STRING_PATTERN |