Skip to content

ImageTransforms ​

Type
Class
Namespace
craft\services
Inherits
craft\services\ImageTransforms » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
4.0.0

Image Transforms service.

An instance of the service is available via Craft::$app->imageTransforms.

View source

Public Properties ​

PropertyDescription
allImageTransformersstring[]
allTransformscraft\models\ImageTransform[]
behaviorsyii\base\Behavior – List of behaviors attached to this component.
dbcraft\db\Connection, array, string – The database connection to use
pendingTransformIndexIdsarray

allImageTransformers ​

Type
string[]
Default value
null
Access
Read-only

View source

allTransforms ​

Type
craft\models\ImageTransform[]
Default value
null

View source

db ​

Type
craft\db\Connection, array, string
Default value
'db'

The database connection to use

View source

pendingTransformIndexIds ​

Type
array
Default value
null

View source

Public Methods ​

MethodDescription
__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 a component property.
__isset()Checks if a property is set, i.e. defined and not null.
__serialize()Serializer
__set()Sets the value of a component property.
__unset()Sets a component property to be 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.
deleteResizedAssetVersion()Delete all the generated thumbnails for the Asset.
deleteTransform()Deletes an asset transform.
deleteTransformById()Deletes an asset transform by its ID.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
eagerLoadTransforms()Eager-loads transform indexes the given list of assets.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
getAllImageTransformers()Return all available image transformers.
getAllTransforms()Returns all named asset transforms.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getImageTransformer()
getTransformByHandle()Returns an asset transform by its handle.
getTransformById()Returns an asset transform by its ID.
getTransformByUid()Returns an asset transform by its UID.
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 for this component.
init()Initializes the object.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
saveTransform()Saves an asset transform.
trigger()Triggers an event.

__serialize() ​

Serializer

View source

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 ​

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

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 ​

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:

::: code

twig
[{width: 1000, height: 600}, '1.5x', '2x', '3x']
php
[['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 ​

  • $assets (craft\elements\Asset[], array) – The assets or asset data to eager-load transforms for
  • $transforms (array) – The transform definitions to eager-load

getAllImageTransformers() ​

Return all available image transformers.

View source

Returns ​

string[]

getAllTransforms() ​

Returns all named asset transforms.

View source

Returns ​

craft\models\ImageTransform[]

getImageTransformer() ​

View source

Arguments ​

  • $type (class-string<\craft\services\T>)
  • $config (array)

Returns ​

\craft\services\T

Throws ​

getTransformByHandle() ​

Returns an asset transform by its handle.

View source

Arguments ​

Returns ​

craft\models\ImageTransform, null

getTransformById() ​

Returns an asset transform by its ID.

View source

Arguments ​

Returns ​

craft\models\ImageTransform, null

getTransformByUid() ​

Returns an asset transform by its UID.

View source

Arguments ​

Returns ​

craft\models\ImageTransform, null

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

saveTransform() ​

Saves an asset transform.

View source

Arguments ​

Returns ​

boolean

Throws ​

Events ​

EVENT_AFTER_DELETE_IMAGE_TRANSFORM ​

Type
craft\services\AssetTransformEvent

The event that is triggered after an image transform is deleted


EVENT_AFTER_SAVE_IMAGE_TRANSFORM ​

Type
craft\services\AssetTransformEvent

The event that is triggered after an image transform is saved


EVENT_BEFORE_APPLY_TRANSFORM_DELETE ​

Type
craft\services\AssetTransformEvent

The event that is triggered before a transform delete is applied to the database.


EVENT_BEFORE_DELETE_IMAGE_TRANSFORM ​

Type
craft\services\AssetTransformEvent

The event that is triggered before an image transform is deleted


EVENT_BEFORE_INVALIDATE_ASSET_TRANSFORMS ​

Type
craft\events\AssetEvent

The event that is triggered before a transform is deleted for an Asset.


EVENT_BEFORE_SAVE_IMAGE_TRANSFORM ​

Type
craft\services\AssetTransformEvent

The event that is triggered before an image transform is saved


EVENT_REGISTER_IMAGE_TRANSFORMERS ​

Type
craft\events\RegisterComponentTypesEvent

The event that is triggered when registering image transformers.