AssetTransforms

Type
Class
Namespace
craft\services
Inherits
craft\services\AssetTransforms » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0

Asset Transforms service.

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

View source

Public Properties

$activeTransformIndex

Signature

public craft\models\AssetTransformIndex, null getActiveTransformIndex ( )
public void setActiveTransformIndex ( craft\models\AssetTransformIndex $index )

$allTransforms

Signature

public craft\models\AssetTransform[] getAllTransforms ( )

$cachedCloudImageSize

Type
integer
Access
Read-only

View source

Signature

public integer getCachedCloudImageSize ( )

$pendingTransformIndexIds

Type
array
Access
Read-only

View source

Signature

public array getPendingTransformIndexIds ( )

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 an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to 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.
deleteQueuedSourceFiles()Delete all image sources queued up for deletion.
deleteResizedAssetVersion()Delete all the generated thumbnails for the Asset.
deleteTransform()Deletes an asset transform.
deleteTransformById()Deletes an asset transform by its ID.
deleteTransformIndex()Delete a transform index by.
deleteTransformIndexDataByAssetId()Delete transform records by an Asset id
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
detectAutoTransformFormat()Detect the auto web-safe format for the Asset. Returns null, if the Asset is not an image.
eagerLoadTransforms()Eager-loads transform indexes for a given set of file IDs.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
ensureTransformUrlByIndexModel()Get a transform URL by the transform index model.
getActiveTransformIndex()
getAllCreatedTransformsForAsset()Get an array of AssetTransformIndex models for all created transforms for an Asset.
getAllTransforms()Returns all named asset transforms.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getCachedCloudImageSize()Get the size of max cached cloud images dimension.
getLocalImageSource()Get a local image source to use for transforms.
getPendingTransformIndexIds()Returns a list of pending transform index IDs.
getTransformByHandle()Returns an asset transform by its handle.
getTransformById()Returns an asset transform by its id.
getTransformFilename()Return the filename used by the Transform Index for the Asset.
getTransformIndex()Get a transform index row. If it doesn't exist - create one.
getTransformIndexModelByAssetIdAndHandle()Get a transform index model by a row id.
getTransformIndexModelById()Get a transform index model by a row id.
getTransformSubfolder()Return a subfolder used by the Transform Index for the Asset.
getTransformSubpath()Returns the path to a transform, relative to the asset's folder.
getTransformUri()Returns the URI for a transform, relative to the asset's folder.
getUrlForTransformByAssetAndTransformIndex()Get URL for Transform by the transform index model.
getUrlForTransformByIndexId()Get URL for Transform by TransformIndexId.
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.
init()Initializes the object.
normalizeTransform()Normalize a transform from handle or a set of properties to an AssetTransform.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
queueSourceForDeletingIfNecessary()Deletes an image local source if required by config.
saveTransform()Saves an asset transform.
setActiveTransformIndex()
storeLocalSource()Store a local image copy to a destination path.
storeTransformIndexData()Store a transform index data by it's model.
trigger()Triggers an event.
validateTransformIndexResult()Validates a transform index result to see if the index is still valid for a given file.

deleteAllTransformData()

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

View source

Arguments

Signature

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

deleteCreatedTransformsForAsset()

Delete created transforms for an Asset.

View source

Arguments

Throws

Signature

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

deleteQueuedSourceFiles()

Delete all image sources queued up for deletion.

View source

Signature

public void deleteQueuedSourceFiles ( )

deleteResizedAssetVersion()

Delete all the generated thumbnails for the Asset.

View source

Arguments

Signature

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

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

Throws

Signature

public boolean deleteTransform ( $transform )

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

Signature

public boolean deleteTransformById ( \craft\services\int $transformId )

deleteTransformIndex()

Delete a transform index by.

View source

Arguments

Signature

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

deleteTransformIndexDataByAssetId()

Delete transform records by an Asset id

View source

Arguments

Signature

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

detectAutoTransformFormat()

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

View source

Arguments

Returns

mixed, string

Throws

Signature

public mixed, string detectAutoTransformFormat ( craft\elements\Asset $asset )

eagerLoadTransforms()

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

View source

Arguments

  • $assets (craft\elements\Asset[]) – The files to eager-load tranforms for
  • $transforms (array) – The transform definitions to eager-load

Signature

public void eagerLoadTransforms ( array $assets, array $transforms )

ensureTransformUrlByIndexModel()

Get a transform URL by the transform index model.

View source

Arguments

Returns

string

Throws

Signature

public string ensureTransformUrlByIndexModel ( craft\models\AssetTransformIndex $index )

getActiveTransformIndex()

Signature

public craft\models\AssetTransformIndex, null getActiveTransformIndex ( )

getAllCreatedTransformsForAsset()

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

View source

Arguments

Returns

array

Signature

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

getAllTransforms()

Returns all named asset transforms.

View source

Returns

craft\models\AssetTransform[]

Signature

public craft\models\AssetTransform[] getAllTransforms ( )

getCachedCloudImageSize()

Get the size of max cached cloud images dimension.

View source

Returns

integer

Signature

public integer getCachedCloudImageSize ( )

getLocalImageSource()

Get a local image source to use for transforms.

View source

Arguments

Returns

string

Throws

Signature

public string getLocalImageSource ( craft\elements\Asset $asset )

getPendingTransformIndexIds()

Returns a list of pending transform index IDs.

View source

Returns

array

Signature

public array getPendingTransformIndexIds ( )

getTransformByHandle()

Returns an asset transform by its handle.

View source

Arguments

Returns

craft\models\AssetTransform, null

Signature

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

getTransformById()

Returns an asset transform by its id.

View source

Arguments

Returns

craft\models\AssetTransform, null

Signature

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

getTransformFilename()

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

View source

Arguments

Returns

string

Signature

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

getTransformIndex()

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

View source

Arguments

Returns

craft\models\AssetTransformIndex

Throws

Signature

public craft\models\AssetTransformIndex getTransformIndex ( craft\elements\Asset $asset, $transform )

getTransformIndexModelByAssetIdAndHandle()

Get a transform index model by a row id.

View source

Arguments

Returns

craft\models\AssetTransformIndex, null

Signature

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

getTransformIndexModelById()

Get a transform index model by a row id.

View source

Arguments

Returns

craft\models\AssetTransformIndex, null

Signature

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

getTransformSubfolder()

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

View source

Arguments

Returns

string

Signature

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

getTransformSubpath()

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

View source

Arguments

Returns

string

Signature

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

getTransformUri()

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

View source

Arguments

Returns

string

Signature

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

getUrlForTransformByAssetAndTransformIndex()

Get URL for Transform by the transform index model.

View source

Arguments

Returns

string

Signature

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

getUrlForTransformByIndexId()

Get URL for Transform by TransformIndexId.

View source

Arguments

Returns

string

Signature

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

normalizeTransform()

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

View source

Arguments

Returns

craft\models\AssetTransform, null

Throws

Signature

public craft\models\AssetTransform, null normalizeTransform ( $transform )

queueSourceForDeletingIfNecessary()

Deletes an image local source if required by config.

View source

Arguments

Signature

public void queueSourceForDeletingIfNecessary ( $imageSource )

saveTransform()

Saves an asset transform.

View source

Arguments

Returns

boolean

Throws

Signature

public boolean saveTransform ( craft\models\AssetTransform $transform, \craft\services\bool $runValidation = true )

setActiveTransformIndex()

Signature

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

storeLocalSource()

Store a local image copy to a destination path.

View source

Arguments

Signature

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

storeTransformIndexData()

Store a transform index data by it's model.

View source

Arguments

Returns

craft\models\AssetTransformIndex

Signature

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

validateTransformIndexResult()

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

View source

Arguments

Returns

boolean – Whether the index result is still valid

Signature

public boolean validateTransformIndexResult ( array $result, craft\models\AssetTransform $transform, craft\elements\Asset $asset )

Events

EVENT_AFTER_DELETE_ASSET_TRANSFORM

Type
craft\events\AssetTransformEvent

The event that is triggered after an asset transform is deleted

EVENT_AFTER_DELETE_TRANSFORMS

Type
craft\events\AssetTransformImageEvent

The event that is triggered after deleting generated transforms.

EVENT_AFTER_SAVE_ASSET_TRANSFORM

Type
craft\events\AssetTransformEvent

The event that is triggered after an asset transform is saved

EVENT_BEFORE_DELETE_ASSET_TRANSFORM

Type
craft\events\AssetTransformEvent

The event that is triggered before an asset transform is deleted

EVENT_BEFORE_DELETE_TRANSFORMS

Type
craft\events\AssetTransformImageEvent

The event that is triggered before deleting generated transforms.

EVENT_BEFORE_SAVE_ASSET_TRANSFORM

Type
craft\events\AssetTransformEvent

The event that is triggered before an asset transform is saved

EVENT_GENERATE_TRANSFORM

Type
craft\events\GenerateTransformEvent

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