ImageTransforms

Type
Class
Namespace
craft\services
Inherits
craft\services\ImageTransforms » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
Implements
yii\base\Configurable (opens new window)
Since
4.0.0

Image Transforms service.

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

View source (opens new window)

# Public Properties

# allImageTransformers

Type
string (opens new window)[]
Default value
null
Access
Read-only

View source (opens new window)

# allTransforms

Type
craft\models\ImageTransform[]
Default value
null

View source (opens new window)

# db

Type
craft\db\Connection, array (opens new window), string (opens new window)
Default value
'db'

The database connection to use

View source (opens new window)

# pendingTransformIndexIds

Type
array (opens new window)
Default value
null

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() 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() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
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.
getAllImageTransformers() Return all available image transformers.
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.
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() (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.
off() (opens new window) Detaches an existing event handler from this component.
on() (opens new window) Attaches an event handler to an event.
saveTransform() Saves an asset transform.
trigger() (opens new window) Triggers an event.

# __serialize()

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

# 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

# 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

# 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:

[{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

# getAllImageTransformers()

Return all available image transformers.

View source (opens new window)

Returns

string (opens new window)[]

# getAllTransforms()

Returns all named asset transforms.

View source (opens new window)

Returns

craft\models\ImageTransform[]

# getImageTransformer()

View source (opens new window)

Arguments

Returns

\craft\services\T

Throws

# getTransformByHandle()

Returns an asset transform by its handle.

View source (opens new window)

Arguments

Returns

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

# getTransformById()

Returns an asset transform by its ID.

View source (opens new window)

Arguments

Returns

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

# getTransformByUid()

Returns an asset transform by its UID.

View source (opens new window)

Arguments

Returns

craft\models\ImageTransform, null (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)

# saveTransform()

Saves an asset transform.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

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.