AssetTransforms
- Type
- Class
- Namespace
- craft\services
- Inherits
- craft\services\AssetTransforms » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
- Implements
- yii\base\Configurable (opens new window)
- Since
- 3.0.0
Asset Transforms service.
An instance of the service is available via Craft::$app->assetTransforms
.
View source (opens new window)
# Public Properties
Property | Description |
---|---|
activeTransformIndex | craft\models\AssetTransformIndex, null (opens new window) |
allTransforms | craft\models\AssetTransform[] |
behaviors (opens new window) | yii\base\Behavior (opens new window) – List of behaviors attached to this component. |
cachedCloudImageSize | integer (opens new window) |
db | craft\db\Connection, array (opens new window), string (opens new window) – The database connection to use |
pendingTransformIndexIds | array (opens new window) |
# activeTransformIndex
- Type
- craft\models\AssetTransformIndex, null (opens new window)
- Default value
null
View source (opens new window)
# allTransforms
- Type
- craft\models\AssetTransform[]
- Default value
null
- Access
- Read-only
View source (opens new window)
# cachedCloudImageSize
- Type
- integer (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# db
- Type
- craft\db\Connection, array (opens new window), string (opens new window)
- Default value
'db'
- Since
- 3.5.4
The database connection to use
View source (opens new window)
# pendingTransformIndexIds
- Type
- array (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__clone() (opens new window) | This method is called after the object is created by cloning an existing one. |
__construct() (opens new window) | Constructor. |
__get() (opens new window) | Returns the value of a component property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__serialize() | Serializer |
__set() (opens new window) | Sets the value of a component property. |
__unset() (opens new window) | Sets a component property to be null. |
attachBehavior() (opens new window) | Attaches a behavior to this component. |
attachBehaviors() (opens new window) | Attaches a list of behaviors to the component. |
behaviors() (opens new window) | Returns a list of behaviors that this component should behave as. |
canGetProperty() (opens new window) | Returns a value indicating whether a property can be read. |
canSetProperty() (opens new window) | Returns a value indicating whether a property can be set. |
className() (opens new window) | Returns the fully qualified name of this class. |
deleteAllTransformData() | Deletes all transform data (including thumbs and sources) associated with an asset. |
deleteCreatedTransformsForAsset() | Deletes transforms for an asset. |
deleteQueuedSourceFiles() | Delete all image sources queued up for deletion. |
deleteResizedAssetVersion() | Deletes all the generated thumbnails for an asset. |
deleteTransform() | Deletes an asset transform. |
deleteTransformById() | Deletes an asset transform by its ID. |
deleteTransformIndex() | Delete a transform index by. |
deleteTransformIndexDataByAssetId() | Deletes transform records by an asset ID. |
detachBehavior() (opens new window) | Detaches a behavior from the component. |
detachBehaviors() (opens new window) | Detaches all behaviors from the component. |
detectAutoTransformFormat() | Detect the auto web-safe format for as asset. Returns null if the asset is not an image. |
eagerLoadTransforms() | Eager-loads transform indexes the given list of assets. |
ensureBehaviors() (opens new window) | Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component. |
ensureTransformUrlByIndexModel() | Get a transform URL by the transform index model. |
extendTransform() | Extend a transform by taking an existing transform and overriding its parameters. |
getActiveTransformIndex() | |
getAllCreatedTransformsForAsset() | Returns an array of craft\models\AssetTransformIndex objects for all created transforms for an asset. |
getAllTransforms() | Returns all named asset transforms. |
getBehavior() (opens new window) | Returns the named behavior object. |
getBehaviors() (opens new window) | Returns all behaviors attached to this component. |
getCachedCloudImageSize() | Get the size of max cached cloud images dimension. |
getLocalImageSource() | Get a local image source to use for transforms. |
getPendingTransformIndexIds() | Returns a list of pending transform index IDs. |
getTransformByHandle() | Returns an asset transform by its handle. |
getTransformById() | Returns an asset transform by its ID. |
getTransformByUid() | Returns an asset transform by its UID. |
getTransformFilename() | Returns the filename used by the transform index for an asset. |
getTransformIndex() | Get a transform index row. If it doesn't exist - create one. |
getTransformIndexModelByAssetIdAndHandle() | Returns a transform index model by an asset ID and transform handle. |
getTransformIndexModelById() | Returns a transform index model by its ID. |
getTransformSubfolder() | Returns a subfolder used by the transform index for an asset. |
getTransformSubpath() | Returns the path to a transform, relative to the asset's folder. |
getTransformUri() | Returns the URI for a transform, relative to the asset's folder. |
getUrlForTransformByAssetAndTransformIndex() | Get URL for Transform by the transform index model. |
getUrlForTransformByIndexId() | Get URL for Transform by TransformIndexId. |
handleChangedTransform() | Handle transform change. |
handleDeletedTransform() | Handle transform being deleted |
hasEventHandlers() (opens new window) | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() (opens new window) | Returns a value indicating whether a method is defined. |
hasProperty() (opens new window) | Returns a value indicating whether a property is defined for this component. |
init() | Initializes the object. |
normalizeTransform() | Normalize a transform from handle or a set of properties to an AssetTransform. |
off() (opens new window) | Detaches an existing event handler from this component. |
on() (opens new window) | Attaches an event handler to an event. |
queueSourceForDeletingIfNecessary() | Deletes an image local source if required by config. |
saveTransform() | Saves an asset transform. |
setActiveTransformIndex() | |
storeLocalSource() | Store a local image copy to a destination path. |
storeTransformIndexData() | Store a transform index data by it's model. |
trigger() (opens new window) | Triggers an event. |
validateTransformIndexResult() | Validates a transform index result to see if the index is still valid for a given asset. |
# __serialize()
- Since
- 3.5.14
Serializer
View source (opens new window)
# deleteAllTransformData()
Deletes all transform data (including thumbs and sources) associated with an asset.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)
# deleteCreatedTransformsForAsset()
Deletes transforms for an asset.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)
Throws
- craft\errors\VolumeException
if something went very wrong when deleting a transform
# deleteQueuedSourceFiles()
Delete all image sources queued up for deletion.
View source (opens new window)
# deleteResizedAssetVersion()
Deletes all the generated thumbnails for an asset.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)
# deleteTransform()
Deletes an asset transform.
Note that passing an ID to this function is now deprecated. Use deleteTransformById() instead.
View source (opens new window)
Arguments
$transform
(integer (opens new window), craft\models\AssetTransform) – The transform
Returns
boolean (opens new window) – Whether the transform was deleted
Throws
- yii\db\Exception (opens new window)
on DB error
# deleteTransformById()
Deletes an asset transform by its ID.
View source (opens new window)
Arguments
$transformId
(integer (opens new window)) – The transform's ID
Returns
boolean (opens new window) – Whether the transform was deleted.
Throws
- yii\db\Exception (opens new window)
on DB error
# deleteTransformIndex()
Delete a transform index by.
View source (opens new window)
Arguments
$indexId
(integer (opens new window))
# deleteTransformIndexDataByAssetId()
Deletes transform records by an asset ID.
View source (opens new window)
Arguments
$assetId
(integer (opens new window))
# detectAutoTransformFormat()
Detect the auto web-safe format for as asset. Returns null
if the asset is not an image.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)
Returns
mixed
, string (opens new window)
Throws
- craft\errors\AssetLogicException
If attempting to detect an image format for a non-image.
# eagerLoadTransforms()
Eager-loads transform indexes the given list of assets.
You can include srcset
-style sizes (e.g. 100w
or 2x
) following a normal transform definition, for example:
When a srcset
-style size is encountered, the preceding normal transform definition will be used as a
reference when determining the resulting transform dimensions.
View source (opens new window)
Arguments
$assets
(craft\elements\Asset[], array (opens new window)) – The assets or asset data to eager-load transforms for$transforms
(array (opens new window)) – The transform definitions to eager-load
# ensureTransformUrlByIndexModel()
Get a transform URL by the transform index model.
View source (opens new window)
Arguments
$index
(craft\models\AssetTransformIndex)
Returns
Throws
- craft\errors\AssetTransformException
If there was an error generating the transform.
# extendTransform()
Extend a transform by taking an existing transform and overriding its parameters.
View source (opens new window)
Arguments
$transform
(craft\models\AssetTransform)$parameters
(array (opens new window))
Returns
# getActiveTransformIndex()
View source (opens new window)
Returns
craft\models\AssetTransformIndex, null (opens new window)
# getAllCreatedTransformsForAsset()
Returns an array of craft\models\AssetTransformIndex objects for all created transforms for an asset.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)
Returns
# getAllTransforms()
Returns all named asset transforms.
View source (opens new window)
Returns
# getCachedCloudImageSize()
Get the size of max cached cloud images dimension.
View source (opens new window)
Returns
# getLocalImageSource()
Get a local image source to use for transforms.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)
Returns
Throws
- craft\errors\VolumeException
If there was an error downloading the remote file. - craft\errors\VolumeObjectNotFoundException
If the file cannot be found.
# getPendingTransformIndexIds()
Returns a list of pending transform index IDs.
View source (opens new window)
Returns
# getTransformByHandle()
Returns an asset transform by its handle.
View source (opens new window)
Arguments
$handle
(string (opens new window))
Returns
craft\models\AssetTransform, null (opens new window)
# getTransformById()
Returns an asset transform by its ID.
View source (opens new window)
Arguments
Returns
craft\models\AssetTransform, null (opens new window)
# getTransformByUid()
- Since
- 3.1.0
Returns an asset transform by its UID.
View source (opens new window)
Arguments
$uid
(string (opens new window))
Returns
craft\models\AssetTransform, null (opens new window)
# getTransformFilename()
Returns the filename used by the transform index for an asset.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)$index
(craft\models\AssetTransformIndex)
Returns
# getTransformIndex()
Get a transform index row. If it doesn't exist - create one.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)$transform
(craft\models\AssetTransform, string (opens new window), array (opens new window), null (opens new window))
Returns
craft\models\AssetTransformIndex
Throws
- craft\errors\AssetTransformException
if the transform cannot be found by the handle
# getTransformIndexModelByAssetIdAndHandle()
Returns a transform index model by an asset ID and transform handle.
View source (opens new window)
Arguments
$assetId
(integer (opens new window))$transformHandle
(string (opens new window))
Returns
craft\models\AssetTransformIndex, null (opens new window)
# getTransformIndexModelById()
Returns a transform index model by its ID.
View source (opens new window)
Arguments
$transformId
(integer (opens new window))
Returns
craft\models\AssetTransformIndex, null (opens new window)
# getTransformSubfolder()
Returns a subfolder used by the transform index for an asset.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)$index
(craft\models\AssetTransformIndex)
Returns
# getTransformSubpath()
Returns the path to a transform, relative to the asset's folder.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)$index
(craft\models\AssetTransformIndex)
Returns
# getTransformUri()
Returns the URI for a transform, relative to the asset's folder.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)$index
(craft\models\AssetTransformIndex)
Returns
# getUrlForTransformByAssetAndTransformIndex()
Get URL for Transform by the transform index model.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)$transformIndexModel
(craft\models\AssetTransformIndex)
Returns
# getUrlForTransformByIndexId()
Get URL for Transform by TransformIndexId.
View source (opens new window)
Arguments
$transformId
(integer (opens new window))
Returns
# handleChangedTransform()
Handle transform change.
View source (opens new window)
Arguments
$event
(craft\events\ConfigEvent)
# handleDeletedTransform()
Handle transform being deleted
View source (opens new window)
Arguments
$event
(craft\events\ConfigEvent)
# init()
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
View source (opens new window)
# normalizeTransform()
Normalize a transform from handle or a set of properties to an AssetTransform.
View source (opens new window)
Arguments
$transform
(craft\models\AssetTransform, string (opens new window), array (opens new window), null (opens new window))
Returns
craft\models\AssetTransform, null (opens new window)
Throws
- craft\errors\AssetTransformException
if $transform is an invalid transform handle
# queueSourceForDeletingIfNecessary()
Deletes an image local source if required by config.
View source (opens new window)
Arguments
$imageSource
(string (opens new window))
# saveTransform()
Saves an asset transform.
View source (opens new window)
Arguments
$transform
(craft\models\AssetTransform) – The transform to be saved$runValidation
(boolean (opens new window)) – Whether the transform should be validated
Returns
Throws
- craft\errors\AssetTransformException
If attempting to update a non-existing transform.
# setActiveTransformIndex()
View source (opens new window)
Arguments
$index
(craft\models\AssetTransformIndex)
# 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))
# storeTransformIndexData()
Store a transform index data by it's model.
View source (opens new window)
Arguments
$index
(craft\models\AssetTransformIndex)
Returns
craft\models\AssetTransformIndex
# validateTransformIndexResult()
Validates a transform index result to see if the index is still valid for a given asset.
View source (opens new window)
Arguments
$result
(array (opens new window))$transform
(craft\models\AssetTransform)$asset
(craft\elements\Asset, array (opens new window)) – The asset object or a raw database result
Returns
boolean (opens new window) – Whether the index result is still valid
# Constants
Constant | Description |
---|---|
CONFIG_TRANSFORM_KEY |
# Events
# EVENT_AFTER_DELETE_ASSET_TRANSFORM
The event that is triggered after an asset transform is deleted
# EVENT_AFTER_DELETE_TRANSFORMS
The event that is triggered after deleting generated transforms.
# EVENT_AFTER_SAVE_ASSET_TRANSFORM
The event that is triggered after an asset transform is saved
# EVENT_BEFORE_APPLY_TRANSFORM_DELETE
- Type
- craft\events\AssetTransformEvent
- Since
- 3.1.0
The event that is triggered before a transform delete is applied to the database.
# EVENT_BEFORE_DELETE_ASSET_TRANSFORM
The event that is triggered before an asset transform is deleted
# EVENT_BEFORE_DELETE_TRANSFORMS
The event that is triggered before deleting generated transforms.
# EVENT_BEFORE_SAVE_ASSET_TRANSFORM
The event that is triggered before an asset transform is saved
# EVENT_GENERATE_TRANSFORM
The event that is triggered when a transform is being generated for an asset.
← AssetIndexer Assets →