AssetTransforms

Type
Class
Namespace
craft\services
Inherits
craft\services\AssetTransforms » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
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

# Public Properties

# activeTransformIndex

Type
craft\models\AssetTransformIndex, null

View source

# allTransforms

Type
craft\models\AssetTransform[]
Access
Read-only

View source

# cachedCloudImageSize

Type
integer
Access
Read-only

View source

# db

Type
craft\db\Connection, array, string
Since
3.5.4

The database connection to use

View source

# pendingTransformIndexIds

Type
array
Access
Read-only

View source

# Public Methods

Method Description
__call() Calls the named method which is not a class method.
__clone() This method is called after the object is created by cloning an existing one.
__construct() Constructor.
__get() Returns the value of an object property.
__isset() Checks if a property is set, i.e. defined and not null.
__set() Sets value of an object property.
__unset() Sets an object property to null.
attachBehavior() Attaches a behavior to this component.
attachBehaviors() Attaches a list of behaviors to the component.
behaviors() Returns a list of behaviors that this component should behave as.
canGetProperty() Returns a value indicating whether a property can be read.
canSetProperty() Returns a value indicating whether a property can be set.
className() 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() Detaches a behavior from the component.
detachBehaviors() 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() Makes sure that the behaviors declared in behaviors() 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() Returns the named behavior object.
getBehaviors() 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() Returns a value indicating whether there is any handler attached to the named event.
hasMethod() Returns a value indicating whether a method is defined.
hasProperty() 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() Detaches an existing event handler from this component.
on() 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() Triggers an event.
validateTransformIndexResult() Validates a transform index result to see if the index is still valid for a given file.

# deleteAllTransformData()

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

View source

Arguments

# deleteCreatedTransformsForAsset()

Delete created transforms for an Asset.

View source

Arguments

Throws

# deleteQueuedSourceFiles()

Delete all image sources queued up for deletion.

View source

# deleteResizedAssetVersion()

Delete all the generated thumbnails for the Asset.

View source

Arguments

# deleteTransform()

Deletes an asset transform.

Note that passing an ID to this function is now deprecated. Use deleteTransformById() instead.

View source

Arguments

Returns

boolean – Whether the transform was deleted

Throws

# deleteTransformById()

Deletes an asset transform by its ID.

View source

Arguments

  • $transformId (integer) – The transform's ID

Returns

boolean – Whether the transform was deleted.

Throws

# deleteTransformIndex()

Delete a transform index by.

View source

Arguments

# deleteTransformIndexDataByAssetId()

Delete transform records by an Asset id

View source

Arguments

# detectAutoTransformFormat()

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

View source

Arguments

Returns

mixed, string

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

Arguments

# ensureTransformUrlByIndexModel()

Get a transform URL by the transform index model.

View source

Arguments

Returns

string

Throws

# extendTransform()

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

View source

Arguments

Returns

craft\models\AssetTransform

# getActiveTransformIndex()

View source

Returns

craft\models\AssetTransformIndex, null

# getAllCreatedTransformsForAsset()

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

View source

Arguments

Returns

array

# getAllTransforms()

Returns all named asset transforms.

View source

Returns

craft\models\AssetTransform[]

# getCachedCloudImageSize()

Get the size of max cached cloud images dimension.

View source

Returns

integer

# getLocalImageSource()

Get a local image source to use for transforms.

View source

Arguments

Returns

string

Throws

# getPendingTransformIndexIds()

Returns a list of pending transform index IDs.

View source

Returns

array

# getTransformByHandle()

Returns an asset transform by its handle.

View source

Arguments

Returns

craft\models\AssetTransform, null

# getTransformById()

Returns an asset transform by its ID.

View source

Arguments

Returns

craft\models\AssetTransform, null

# getTransformByUid()

Since
3.1.0

Returns an asset transform by its UID.

View source

Arguments

Returns

craft\models\AssetTransform, null

# getTransformFilename()

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

View source

Arguments

Returns

string

# getTransformIndex()

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

View source

Arguments

Returns

craft\models\AssetTransformIndex

Throws

# getTransformIndexModelByAssetIdAndHandle()

Get a transform index model by a row id.

View source

Arguments

Returns

craft\models\AssetTransformIndex, null

# getTransformIndexModelById()

Get a transform index model by a row id.

View source

Arguments

Returns

craft\models\AssetTransformIndex, null

# getTransformSubfolder()

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

View source

Arguments

Returns

string

# getTransformSubpath()

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

View source

Arguments

Returns

string

# getTransformUri()

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

View source

Arguments

Returns

string

# getUrlForTransformByAssetAndTransformIndex()

Get URL for Transform by the transform index model.

View source

Arguments

Returns

string

# getUrlForTransformByIndexId()

Get URL for Transform by TransformIndexId.

View source

Arguments

Returns

string

# handleChangedTransform()

Handle transform change.

View source

Arguments

# handleDeletedTransform()

Handle transform being deleted

View source

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

# normalizeTransform()

Normalize a transform from handle or a set of properties to an AssetTransform.

View source

Arguments

Returns

craft\models\AssetTransform, null

Throws

# queueSourceForDeletingIfNecessary()

Deletes an image local source if required by config.

View source

Arguments

# saveTransform()

Saves an asset transform.

View source

Arguments

Returns

boolean

Throws

# setActiveTransformIndex()

View source

Arguments

# storeLocalSource()

Store a local image copy to a destination path.

View source

Arguments

# storeTransformIndexData()

Store a transform index data by it's model.

View source

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

Arguments

Returns

boolean – 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.