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
Property | Description |
---|---|
allImageTransformers | string (opens new window)[] |
allTransforms | craft\models\ImageTransform[] |
behaviors (opens new window) | yii\base\Behavior (opens new window) – List of behaviors attached to this component. |
db | craft\db\Connection, array (opens new window), string (opens new window) – The database connection to use |
pendingTransformIndexIds | array (opens new window) |
# 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
$asset
(craft\elements\Asset)
# deleteCreatedTransformsForAsset()
Delete created transforms for an Asset.
View source (opens new window)
Arguments
$asset
(craft\elements\Asset)
# deleteResizedAssetVersion()
Delete all the generated thumbnails for the 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
(craft\models\ImageTransform) – The transform
Returns
boolean (opens new window) – Whether the transform was deleted
# 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
# 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
# getAllImageTransformers()
Return all available image transformers.
View source (opens new window)
Returns
# getAllTransforms()
Returns all named asset transforms.
View source (opens new window)
Returns
# getImageTransformer()
View source (opens new window)
Arguments
$type
(string (opens new window))$config
(array (opens new window))
Returns
\craft\services\T
Throws
# getTransformByHandle()
Returns an asset transform by its handle.
View source (opens new window)
Arguments
$handle
(string (opens new window))
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
$uid
(string (opens new window))
Returns
craft\models\ImageTransform, null (opens new window)
# 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)
# saveTransform()
Saves an asset transform.
View source (opens new window)
Arguments
$transform
(craft\models\ImageTransform) – The transform to be saved$runValidation
(boolean (opens new window)) – Whether the transform should be validated
Returns
Throws
- craft\errors\ImageTransformException
If attempting to update a non-existing transform.
# Events
# EVENT_AFTER_DELETE_IMAGE_TRANSFORM
- Type
craft\services\AssetTransformEvent
The event that is triggered after an asset transform is deleted
# EVENT_AFTER_SAVE_IMAGE_TRANSFORM
- Type
craft\services\AssetTransformEvent
The event that is triggered after an asset 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 asset transform is deleted
# EVENT_BEFORE_INVALIDATE_ASSET_TRANSFORMS
The event that is triggered when a transform is being generated for an Asset.
# EVENT_BEFORE_SAVE_IMAGE_TRANSFORM
- Type
craft\services\AssetTransformEvent
The event that is triggered before an asset transform is saved
# EVENT_REGISTER_IMAGE_TRANSFORMERS
The event that is triggered when registering image transformers.