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 Asset Transforms service is globally accessible in Craft via Craft::$app->assetTransforms.

View source (opens new window)

# Public Properties

# 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 an object property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__serialize() Serializer
__set() (opens new window) Sets value of an object property.
__unset() (opens new window) Sets an object property to 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() Delete ALL transform data (including thumbs and sources) associated with the Asset.
deleteCreatedTransformsForAsset() Delete created transforms for an Asset.
deleteQueuedSourceFiles() Delete all image sources queued up for deletion.
deleteResizedAssetVersion() Delete all the generated thumbnails for the Asset.
deleteTransform() Deletes an asset transform.
deleteTransformById() Deletes an asset transform by its ID.
deleteTransformIndex() Delete a transform index by.
deleteTransformIndexDataByAssetId() Delete 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 the Asset. Returns null, if the Asset is not an image.
eagerLoadTransforms() Eager-loads transform indexes for a given set of file IDs.
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() Get an array of AssetTransformIndex models 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() Return the filename used by the Transform Index for the Asset.
getTransformIndex() Get a transform index row. If it doesn't exist - create one.
getTransformIndexModelByAssetIdAndHandle() Get a transform index model by a row id.
getTransformIndexModelById() Get a transform index model by a row id.
getTransformSubfolder() Return a subfolder used by the Transform Index for the 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.
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 file.

# __serialize()

Since
3.5.14

Serializer

View source (opens new window)

# deleteAllTransformData()

Delete ALL transform data (including thumbs and sources) associated with the Asset.

View source (opens new window)

Arguments

# deleteCreatedTransformsForAsset()

Delete created transforms for an Asset.

View source (opens new window)

Arguments

Throws

# deleteQueuedSourceFiles()

Delete all image sources queued up for deletion.

View source (opens new window)

# deleteResizedAssetVersion()

Delete all the generated thumbnails for the Asset.

View source (opens new window)

Arguments

# 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

Returns

boolean (opens new window) – Whether the transform was deleted

Throws

# deleteTransformById()

Deletes an asset transform by its ID.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the transform was deleted.

Throws

# deleteTransformIndex()

Delete a transform index by.

View source (opens new window)

Arguments

# deleteTransformIndexDataByAssetId()

Delete transform records by an Asset id

View source (opens new window)

Arguments

# detectAutoTransformFormat()

Detect the auto web-safe format for the Asset. Returns null, if the Asset is not an image.

View source (opens new window)

Arguments

Returns

mixed, string (opens new window)

Throws

# eagerLoadTransforms()

Eager-loads transform indexes for a given set of file IDs.

You can include srcset-style sizes (e.g. 100w or 2x) following a normal transform definition, for example:

[{width: 1000, height: 600}, '1.5x', '2x', '3x']

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

# ensureTransformUrlByIndexModel()

Get a transform URL by the transform index model.

View source (opens new window)

Arguments

Returns

string (opens new window)

Throws

# extendTransform()

Extend a transform by taking an existing transform and overriding its parameters.

View source (opens new window)

Arguments

Returns

craft\models\AssetTransform

# getActiveTransformIndex()

View source (opens new window)

Returns

craft\models\AssetTransformIndex, null (opens new window)

# getAllCreatedTransformsForAsset()

Get an array of AssetTransformIndex models for all created transforms for an Asset.

View source (opens new window)

Arguments

Returns

array (opens new window)

# getAllTransforms()

Returns all named asset transforms.

View source (opens new window)

Returns

craft\models\AssetTransform[]

# getCachedCloudImageSize()

Get the size of max cached cloud images dimension.

View source (opens new window)

Returns

integer (opens new window)

# getLocalImageSource()

Get a local image source to use for transforms.

View source (opens new window)

Arguments

Returns

string (opens new window)

Throws

# getPendingTransformIndexIds()

Returns a list of pending transform index IDs.

View source (opens new window)

Returns

array (opens new window)

# getTransformByHandle()

Returns an asset transform by its handle.

View source (opens new window)

Arguments

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

Returns

craft\models\AssetTransform, null (opens new window)

# getTransformFilename()

Return the filename used by the Transform Index for the Asset.

View source (opens new window)

Arguments

Returns

string (opens new window)

# getTransformIndex()

Get a transform index row. If it doesn't exist - create one.

View source (opens new window)

Arguments

Returns

craft\models\AssetTransformIndex

Throws

# getTransformIndexModelByAssetIdAndHandle()

Get a transform index model by a row id.

View source (opens new window)

Arguments

Returns

craft\models\AssetTransformIndex, null (opens new window)

# getTransformIndexModelById()

Get a transform index model by a row id.

View source (opens new window)

Arguments

Returns

craft\models\AssetTransformIndex, null (opens new window)

# getTransformSubfolder()

Return a subfolder used by the Transform Index for the Asset.

View source (opens new window)

Arguments

Returns

string (opens new window)

# getTransformSubpath()

Returns the path to a transform, relative to the asset's folder.

View source (opens new window)

Arguments

Returns

string (opens new window)

# getTransformUri()

Returns the URI for a transform, relative to the asset's folder.

View source (opens new window)

Arguments

Returns

string (opens new window)

# getUrlForTransformByAssetAndTransformIndex()

Get URL for Transform by the transform index model.

View source (opens new window)

Arguments

Returns

string (opens new window)

# getUrlForTransformByIndexId()

Get URL for Transform by TransformIndexId.

View source (opens new window)

Arguments

Returns

string (opens new window)

# handleChangedTransform()

Handle transform change.

View source (opens new window)

Arguments

# handleDeletedTransform()

Handle transform being deleted

View source (opens new window)

Arguments

# 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

Returns

craft\models\AssetTransform, null (opens new window)

Throws

# queueSourceForDeletingIfNecessary()

Deletes an image local source if required by config.

View source (opens new window)

Arguments

# saveTransform()

Saves an asset transform.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

Throws

# setActiveTransformIndex()

View source (opens new window)

Arguments

# storeLocalSource()

Store a local image copy to a destination path.

View source (opens new window)

Arguments

# storeTransformIndexData()

Store a transform index data by it's model.

View source (opens new window)

Arguments

Returns

craft\models\AssetTransformIndex

# validateTransformIndexResult()

Validates a transform index result to see if the index is still valid for a given file.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the index result is still valid

# Constants

Constant Description
CONFIG_TRANSFORM_KEY

# Events

# EVENT_AFTER_DELETE_ASSET_TRANSFORM

Type
craft\events\AssetTransformEvent

The event that is triggered after an asset transform is deleted

# EVENT_AFTER_DELETE_TRANSFORMS

Type
craft\events\AssetTransformImageEvent

The event that is triggered after deleting generated transforms.

# EVENT_AFTER_SAVE_ASSET_TRANSFORM

Type
craft\events\AssetTransformEvent

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

Type
craft\events\AssetTransformEvent

The event that is triggered before an asset transform is deleted

# EVENT_BEFORE_DELETE_TRANSFORMS

Type
craft\events\AssetTransformImageEvent

The event that is triggered before deleting generated transforms.

# EVENT_BEFORE_SAVE_ASSET_TRANSFORM

Type
craft\events\AssetTransformEvent

The event that is triggered before an asset transform is saved

# EVENT_GENERATE_TRANSFORM

Type
craft\events\GenerateTransformEvent

The event that is triggered when a transform is being generated for an Asset.