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
.
Public Properties ​
Property | Description |
---|---|
allImageTransformers | string[] |
allTransforms | craft\models\ImageTransform[] |
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
db | craft\db\Connection, array, string – The database connection to use |
pendingTransformIndexIds | array |
allImageTransformers
​
- Type
- string[]
- Default value
null
- Access
- Read-only
allTransforms
​
- Type
- craft\models\ImageTransform[]
- Default value
null
db
​
- Type
- craft\db\Connection, array, string
- Default value
'db'
The database connection to use
pendingTransformIndexIds
​
- Type
- array
- Default value
null
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 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
deleteAllTransformData()
​
Delete ALL transform data (including thumbs and sources) associated with the Asset.
Arguments ​
$asset
(craft\elements\Asset)
deleteCreatedTransformsForAsset()
​
Delete created transforms for an Asset.
Arguments ​
$asset
(craft\elements\Asset)
deleteResizedAssetVersion()
​
Delete all the generated thumbnails for the Asset.
Arguments ​
$asset
(craft\elements\Asset)
deleteTransform()
​
Deletes an asset transform.
Note that passing an ID to this function is now deprecated. Use deleteTransformById() instead.
Arguments ​
$transform
(craft\models\ImageTransform) – The transform
Returns ​
boolean – Whether the transform was deleted
deleteTransformById()
​
Deletes an asset transform by its ID.
Arguments ​
$transformId
(integer) – The transform's ID
Returns ​
boolean – Whether the transform was deleted.
Throws ​
- yii\db\Exception
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:
::: code
[{width: 1000, height: 600}, '1.5x', '2x', '3x']
[['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.
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.
Returns ​
string[]
getAllTransforms()
​
Returns all named asset transforms.
Returns ​
getImageTransformer()
​
Arguments ​
$type
(class-string<\craft\services\T>
)$config
(array)
Returns ​
\craft\services\T
Throws ​
getTransformByHandle()
​
Returns an asset transform by its handle.
Arguments ​
$handle
(string)
Returns ​
craft\models\ImageTransform, null
getTransformById()
​
Returns an asset transform by its ID.
Arguments ​
$id
(integer)
Returns ​
craft\models\ImageTransform, null
getTransformByUid()
​
Returns an asset transform by its UID.
Arguments ​
$uid
(string)
Returns ​
craft\models\ImageTransform, null
handleChangedTransform()
​
Handle transform change.
Arguments ​
$event
(craft\events\ConfigEvent)
handleDeletedTransform()
​
Handle transform being deleted
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.
saveTransform()
​
Saves an asset transform.
Arguments ​
$transform
(craft\models\ImageTransform) – The transform to be saved$runValidation
(boolean) – 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 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 ​
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 ​
The event that is triggered when registering image transformers.