Craft 3 Class Reference

Class craft\services\AssetTransforms

Inheritance
craft\services\AssetTransforms » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/services/AssetTransforms.php

Asset Transforms service.

An instance of the Asset Transforms service is globally accessible in Craft via Craft::$app->assetTransforms.

Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
deleteAllTransformData() Delete ALL transform data (including thumbs and sources) associated with the Asset. craft\services\AssetTransforms
deleteCreatedTransformsForAsset() Delete created transforms for an Asset. craft\services\AssetTransforms
deleteQueuedSourceFiles() Delete all image sources queued up for deletion. craft\services\AssetTransforms
deleteResizedAssetVersion() Delete all the generated thumbnails for the Asset. craft\services\AssetTransforms
deleteTransform() Deletes an asset transform by its id. craft\services\AssetTransforms
deleteTransformIndex() Delete a transform index by. craft\services\AssetTransforms
deleteTransformIndexDataByAssetId() Delete transform records by an Asset id craft\services\AssetTransforms
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
detectAutoTransformFormat() Detect the auto web-safe format for the Asset. Returns null, if the Asset is not an image. craft\services\AssetTransforms
eagerLoadTransforms() Eager-loads transform indexes for a given set of file IDs. craft\services\AssetTransforms
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
ensureTransformUrlByIndexModel() Get a transform URL by the transform index model. craft\services\AssetTransforms
getActiveTransformIndex() craft\services\AssetTransforms
getAllCreatedTransformsForAsset() Get an array of AssetTransformIndex models for all created transforms for an Asset. craft\services\AssetTransforms
getAllTransforms() Returns all named asset transforms. craft\services\AssetTransforms
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getCachedCloudImageSize() Get the size of max cached cloud images dimension. craft\services\AssetTransforms
getLocalImageSource() Get a local image source to use for transforms. craft\services\AssetTransforms
getPendingTransformIndexIds() Returns a list of pending transform index IDs. craft\services\AssetTransforms
getTransformByHandle() Returns an asset transform by its handle. craft\services\AssetTransforms
getTransformById() Returns an asset transform by its id. craft\services\AssetTransforms
getTransformFilename() Return the filename used by the Transform Index for the Asset. craft\services\AssetTransforms
getTransformIndex() Get a transform index row. If it doesn't exist - create one. craft\services\AssetTransforms
getTransformIndexModelByAssetIdAndHandle() Get a transform index model by a row id. craft\services\AssetTransforms
getTransformIndexModelById() Get a transform index model by a row id. craft\services\AssetTransforms
getTransformSubfolder() Return a subfolder used by the Transform Index for the Asset. craft\services\AssetTransforms
getTransformSubpath() Returns the path to a transform, relative to the asset's folder. craft\services\AssetTransforms
getTransformUri() Returns the URI for a transform, relative to the asset's folder. craft\services\AssetTransforms
getUrlForTransformByAssetAndTransformIndex() Get URL for Transform by the transform index model. craft\services\AssetTransforms
getUrlForTransformByIndexId() Get URL for Transform by TransformIndexId. craft\services\AssetTransforms
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
normalizeTransform() Normalize a transform from handle or a set of properties to an AssetTransform. craft\services\AssetTransforms
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
queueSourceForDeletingIfNecessary() Deletes an image local source if required by config. craft\services\AssetTransforms
saveTransform() Saves an asset transform. craft\services\AssetTransforms
setActiveTransformIndex() craft\services\AssetTransforms
storeLocalSource() Store a local image copy to a destination path. craft\services\AssetTransforms
storeTransformIndexData() Store a transform index data by it's model. craft\services\AssetTransforms
trigger() Triggers an event. yii\base\Component
validateTransformIndexResult() Validates a transform index result to see if the index is still valid for a given file. craft\services\AssetTransforms
Events
Event Type Description Defined By
EVENT_AFTER_DELETE_ASSET_TRANSFORM craft\events\AssetTransformEvent The event that is triggered after an asset transform is deleted craft\services\AssetTransforms
EVENT_AFTER_DELETE_TRANSFORMS craft\events\AssetTransformImageEvent The event that is triggered after deleting generated transforms. craft\services\AssetTransforms
EVENT_AFTER_SAVE_ASSET_TRANSFORM craft\events\AssetTransformEvent The event that is triggered after an asset transform is saved craft\services\AssetTransforms
EVENT_BEFORE_DELETE_ASSET_TRANSFORM craft\events\AssetTransformEvent The event that is triggered before an asset transform is deleted craft\services\AssetTransforms
EVENT_BEFORE_DELETE_TRANSFORMS craft\events\AssetTransformImageEvent The event that is triggered before deleting generated transforms. craft\services\AssetTransforms
EVENT_BEFORE_SAVE_ASSET_TRANSFORM craft\events\AssetTransformEvent The event that is triggered before an asset transform is saved craft\services\AssetTransforms
EVENT_GENERATE_TRANSFORM craft\events\GenerateTransformEvent The event that is triggered when a transform is being generated for an Asset. craft\services\AssetTransforms

Method Details

deleteAllTransformData() public method #

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

public void deleteAllTransformData ( craft\elements\Asset $asset )
$asset craft\elements\Asset

deleteCreatedTransformsForAsset() public method #

Delete created transforms for an Asset.

public void deleteCreatedTransformsForAsset ( craft\elements\Asset $asset )
$asset craft\elements\Asset
throws craft\errors\VolumeException if something went very wrong when deleting a transform

deleteQueuedSourceFiles() public method #

Delete all image sources queued up for deletion.

public void deleteQueuedSourceFiles ( )

deleteResizedAssetVersion() public method #

Delete all the generated thumbnails for the Asset.

public void deleteResizedAssetVersion ( craft\elements\Asset $asset )
$asset craft\elements\Asset

deleteTransform() public method #

Deletes an asset transform by its id.

public boolean deleteTransform ( \craft\services\int $transformId )
$transformId integer
throws yii\db\Exception on DB error

deleteTransformIndex() public method #

Delete a transform index by.

public void deleteTransformIndex ( \craft\services\int $indexId )
$indexId integer

deleteTransformIndexDataByAssetId() public method #

Delete transform records by an Asset id

public void deleteTransformIndexDataByAssetId ( \craft\services\int $assetId )
$assetId integer

detectAutoTransformFormat() public method #

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

public mixed, string detectAutoTransformFormat ( craft\elements\Asset $asset )
$asset craft\elements\Asset
throws craft\errors\AssetLogicException If attempting to detect an image format for a non-image.

eagerLoadTransforms() public method #

Eager-loads transform indexes for a given set of file IDs.

public void eagerLoadTransforms ( array $assets, array $transforms )
$assets craft\elements\Asset[] The files to eager-load tranforms for
$transforms array The transform definitions to eager-load

ensureTransformUrlByIndexModel() public method #

Get a transform URL by the transform index model.

public string ensureTransformUrlByIndexModel ( craft\models\AssetTransformIndex $index )
$index craft\models\AssetTransformIndex
throws craft\errors\AssetTransformException If there was an error generating the transform.

getActiveTransformIndex() public method #

public craft\models\AssetTransformIndex, null getActiveTransformIndex ( )

getAllCreatedTransformsForAsset() public method #

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

public array getAllCreatedTransformsForAsset ( craft\elements\Asset $asset )
$asset craft\elements\Asset

getAllTransforms() public method #

Returns all named asset transforms.

public craft\models\AssetTransform[] getAllTransforms ( )

getCachedCloudImageSize() public method #

Get the size of max cached cloud images dimension.

public integer getCachedCloudImageSize ( )

getLocalImageSource() public method #

Get a local image source to use for transforms.

public string getLocalImageSource ( craft\elements\Asset $asset )
$asset craft\elements\Asset
throws craft\errors\VolumeObjectNotFoundException If the file cannot be found.
throws craft\errors\VolumeException If there was an error downloading the remote file.

getPendingTransformIndexIds() public method #

Returns a list of pending transform index IDs.

public array getPendingTransformIndexIds ( )

getTransformByHandle() public method #

Returns an asset transform by its handle.

public craft\models\AssetTransform, null getTransformByHandle ( \craft\services\string $handle )
$handle string

getTransformById() public method #

Returns an asset transform by its id.

public craft\models\AssetTransform, null getTransformById ( \craft\services\int $id )
$id integer

getTransformFilename() public method #

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

public string getTransformFilename ( craft\elements\Asset $asset, craft\models\AssetTransformIndex $index )
$asset craft\elements\Asset
$index craft\models\AssetTransformIndex

getTransformIndex() public method #

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

public craft\models\AssetTransformIndex getTransformIndex ( craft\elements\Asset $asset, $transform )
$asset craft\elements\Asset
$transform craft\models\AssetTransform, string, array, null
throws craft\errors\AssetTransformException if the transform cannot be found by the handle

getTransformIndexModelByAssetIdAndHandle() public method #

Get a transform index model by a row id.

public craft\models\AssetTransformIndex, null getTransformIndexModelByAssetIdAndHandle ( \craft\services\int $assetId, \craft\services\string $transformHandle )
$assetId integer
$transformHandle string

getTransformIndexModelById() public method #

Get a transform index model by a row id.

public craft\models\AssetTransformIndex, null getTransformIndexModelById ( \craft\services\int $transformId )
$transformId integer

getTransformSubfolder() public method #

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

public string getTransformSubfolder ( craft\elements\Asset $asset, craft\models\AssetTransformIndex $index )
$asset craft\elements\Asset
$index craft\models\AssetTransformIndex

getTransformSubpath() public method #

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

public string getTransformSubpath ( craft\elements\Asset $asset, craft\models\AssetTransformIndex $index )
$asset craft\elements\Asset
$index craft\models\AssetTransformIndex

getTransformUri() public method #

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

public string getTransformUri ( craft\elements\Asset $asset, craft\models\AssetTransformIndex $index )
$asset craft\elements\Asset
$index craft\models\AssetTransformIndex

getUrlForTransformByAssetAndTransformIndex() public method #

Get URL for Transform by the transform index model.

public string getUrlForTransformByAssetAndTransformIndex ( craft\elements\Asset $asset, craft\models\AssetTransformIndex $transformIndexModel )
$asset craft\elements\Asset
$transformIndexModel craft\models\AssetTransformIndex

getUrlForTransformByIndexId() public method #

Get URL for Transform by TransformIndexId.

public string getUrlForTransformByIndexId ( \craft\services\int $transformId )
$transformId integer

normalizeTransform() public method #

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

public craft\models\AssetTransform, null normalizeTransform ( $transform )
$transform craft\models\AssetTransform, string, array, null
throws craft\errors\AssetTransformException if $transform is an invalid transform handle

queueSourceForDeletingIfNecessary() public method #

Deletes an image local source if required by config.

public void queueSourceForDeletingIfNecessary ( $imageSource )
$imageSource string

saveTransform() public method #

Saves an asset transform.

public boolean saveTransform ( craft\models\AssetTransform $transform, \craft\services\bool $runValidation true )
$transform craft\models\AssetTransform The transform to be saved
$runValidation boolean Whether the transform should be validated
throws craft\errors\AssetTransformException If attempting to update a non-existing transform.

setActiveTransformIndex() public method #

public void setActiveTransformIndex ( craft\models\AssetTransformIndex $index )
$index craft\models\AssetTransformIndex

storeLocalSource() public method #

Store a local image copy to a destination path.

public void storeLocalSource ( \craft\services\string $source, \craft\services\string $destination '' )
$source string
$destination string

storeTransformIndexData() public method #

Store a transform index data by it's model.

public craft\models\AssetTransformIndex storeTransformIndexData ( craft\models\AssetTransformIndex $index )
$index craft\models\AssetTransformIndex

validateTransformIndexResult() public method #

Validates a transform index result to see if the index is still valid for a given file.

public boolean validateTransformIndexResult ( array $result, craft\models\AssetTransform $transform, craft\elements\Asset $asset )
$result array
$transform craft\models\AssetTransform
$asset craft\elements\Asset
return boolean Whether the index result is still valid

Event Details

EVENT_AFTER_DELETE_ASSET_TRANSFORM event of type craft\events\AssetTransformEvent #

The event that is triggered after an asset transform is deleted

EVENT_AFTER_DELETE_TRANSFORMS event of type craft\events\AssetTransformImageEvent #

The event that is triggered after deleting generated transforms.

EVENT_AFTER_SAVE_ASSET_TRANSFORM event of type craft\events\AssetTransformEvent #

The event that is triggered after an asset transform is saved

EVENT_BEFORE_DELETE_ASSET_TRANSFORM event of type craft\events\AssetTransformEvent #

The event that is triggered before an asset transform is deleted

EVENT_BEFORE_DELETE_TRANSFORMS event of type craft\events\AssetTransformImageEvent #

The event that is triggered before deleting generated transforms.

EVENT_BEFORE_SAVE_ASSET_TRANSFORM event of type craft\events\AssetTransformEvent #

The event that is triggered before an asset transform is saved

EVENT_GENERATE_TRANSFORM event of type craft\events\GenerateTransformEvent #

The event that is triggered when a transform is being generated for an Asset.