class ImageVariant extends Asset implements AssetVariantInterface, ImageInterface (View source)

A user defined variant (working copy) of an original Image asset

Traits

Trait for methods regarding the dimensions of an asset

Properties

protected PersistenceManagerInterface $persistenceManager from  Asset
protected LoggerInterface $systemLogger from  Asset
protected ResourceManager $resourceManager from  Asset
protected ThumbnailService $thumbnailService from  Asset
protected AssetService $assetService from  Asset
protected AssetRepository $assetRepository from  Asset
protected ImportedAssetRepository $importedAssetRepository from  Asset
protected DateTime $lastModified from  Asset
protected string $title from  Asset
protected string $caption from  Asset
protected string $copyrightNotice from  Asset
protected PersistentResource $resource from  Asset
protected Thumbnail> $thumbnails from  Asset
protected Tag> $tags from  Asset
protected AssetCollection> $assetCollections from  Asset
string $assetSourceIdentifier from  Asset
protected array $assetSourcesConfiguration from  Asset
protected AssetSourceInterface[] $assetSources from  Asset
protected int $width from  DimensionsTrait
protected int $height from  DimensionsTrait
protected ImageService $imageService
protected Image $originalAsset
protected AbstractImageAdjustment> $adjustments
protected string $name
protected string $presetIdentifier
protected string $presetVariantName

Methods

__construct(Image $originalAsset)

Constructs a new Image Variant based on the given original

void
initializeObject(int $initializationCause)

Initialize this image variant

void
initialize()

Override this to initialize upon instantiation.

from  Asset
string
getIdentifier()

No description

from  Asset
string
getLabel()

No description

from  Asset
getLastModified()

Returns the last modification timestamp for this asset

from  Asset
void
setResource(PersistentResource $resource)

Setting the image resource on an ImageVariant is not allowed, this method will throw a RuntimeException.

PersistentResource
getResource()

Returns the resource of this image variant

string
getFileExtension()

File extension of the image without leading dot.

string
getMediaType()

Returns the IANA media type of this asset

from  Asset
void
setTitle(string $title)

Setting the title on an ImageVariant is not allowed, this method will throw a RuntimeException.

string
getTitle()

Returns the title of the original image

void
setCaption(string $caption)

Sets the caption of this asset (optional)

from  Asset
string
getCaption()

Returns the caption of the original image

string
getCopyrightNotice()

No description

void
setCopyrightNotice(string $copyrightNotice)

No description

from  Asset
Collection
getTags()

Return the tags assigned to this asset

from  Asset
bool
addTag(Tag $tag)

Add a single tag to this asset

getThumbnail(int $maximumWidth = null, int $maximumHeight = null, string $ratioMode = ImageInterface::RATIOMODE_INSET, bool $allowUpScaling = null)

Returns a thumbnail of this asset

from  Asset
mixed
addThumbnail(Thumbnail $thumbnail)

An internal method which adds a thumbnail which was generated by the ThumbnailService.

from  Asset
void
refresh()

Refreshes this image variant: according to the added adjustments, a new image is rendered and stored as this image variant's resource.

void
setTags(Collection $tags)

Set the tags assigned to this asset

bool
removeTag(Tag $tag)

Remove a single tag from this asset

from  Asset
Collection
getAssetCollections()

Return the asset collections this asset is included in

from  Asset
void
setAssetCollections(Collection $assetCollections)

Set the asset collections that include this asset

from  Asset
void
setAssetSourceIdentifier(string $assetSourceIdentifier)

Set the asset source identifier for this asset

from  Asset
string|null
getAssetSourceIdentifier()

No description

from  Asset
AssetProxyInterface|null
getAssetProxy()

No description

from  Asset
bool
isInUse()

Returns true if the asset is still in use.

from  Asset
int
getUsageCount()

Returns the number of times the asset is in use.

from  Asset
int
getWidth()

Width of the image in pixels

int
getHeight()

Height of the image in pixels

bool
hasDimensions()

Does the asset have dimensions

float
getAspectRatio(bool $respectOrientation = false)

Edge / aspect ratio of the image

string
getOrientation()

Orientation of this image, i.e. portrait, landscape or square

bool
isOrientationSquare()

Whether this image is square aspect ratio and therefore has a square orientation

bool
isOrientationLandscape()

Whether this image is in landscape orientation

bool
isOrientationPortrait()

Whether this image is in portrait orientation

getOriginalAsset()

Returns the original image this variant is based on

void
setName(string $name)

Sets a name which can be used for identifying this variant

string
getName()

Returns the name

void
addVariant(ImageVariant $variant)

Adding variants to variants is not supported.

array
getVariants()

Retrieving variants from variants is not supported (no-operation)

void
setPresetIdentifier(string $presetIdentifier)

Sets the identifier of the image variant preset which created this variant (if any)

string|null
getPresetIdentifier()

Returns the identifier of the image variant preset which created this variant (if any)

void
setPresetVariantName(string $presetVariantName)

No description

string|null
getPresetVariantName()

No description

void
addAdjustment(ImageAdjustmentInterface $adjustment)

Adds the given adjustment to the list of adjustments applied to this image variant.

void
addAdjustments(array $adjustments)

Adds the given adjustments to the list of adjustments applied to this image variant.

void
applyAdjustment(ImageAdjustmentInterface $adjustment)

Apply the given adjustment to the image variant.

Collection
getAdjustments()

No description

void
renderResource()

Tells the ImageService to render the resource of this ImageVariant according to the existing adjustments.

Details

__construct(Image $originalAsset)

Constructs a new Image Variant based on the given original

Parameters

Image $originalAsset

The original Image asset this variant is derived from

void initializeObject(int $initializationCause)

Initialize this image variant

This method will generate the resource of this asset when this object has just been newly created. We can't run renderResource() in the constructor since not all dependencies have been injected then. Generating resources lazily in the getResource() method is not feasible either, because getters will be triggered by the validation mechanism on flushing the persistence which will result in undefined behavior.

We don't call refresh() here because we only want the resource to be rendered, not all other refresh actions from parent classes being executed.

Parameters

int $initializationCause

Return Value

void

Exceptions

Exception
ImageFileException
InvalidConfigurationException

protected void initialize()

Override this to initialize upon instantiation.

Return Value

void

string getIdentifier()

No description

Return Value

string

string getLabel()

No description

Return Value

string

DateTime getLastModified()

Returns the last modification timestamp for this asset

Return Value

DateTime

The date and time of last modification.

void setResource(PersistentResource $resource)

Setting the image resource on an ImageVariant is not allowed, this method will throw a RuntimeException.

Parameters

PersistentResource $resource

Return Value

void

Exceptions

RuntimeException

PersistentResource getResource()

Returns the resource of this image variant

Return Value

PersistentResource

string getFileExtension()

File extension of the image without leading dot.

This will return the file extension of the original image as this should not be different in image variants

Return Value

string

string getMediaType()

Returns the IANA media type of this asset

Return Value

string

void setTitle(string $title)

Setting the title on an ImageVariant is not allowed, this method will throw a RuntimeException.

Parameters

string $title

Return Value

void

Exceptions

RuntimeException

string getTitle()

Returns the title of the original image

Return Value

string

Title of the asset

void setCaption(string $caption)

Sets the caption of this asset (optional)

Parameters

string $caption

Return Value

void

string getCaption()

Returns the caption of the original image

Return Value

string

string getCopyrightNotice()

No description

Return Value

string

void setCopyrightNotice(string $copyrightNotice)

No description

Parameters

string $copyrightNotice

Return Value

void

Collection getTags()

Return the tags assigned to this asset

Return Value

Collection

bool addTag(Tag $tag)

Add a single tag to this asset

Parameters

Tag $tag

The tag to add

Return Value

bool

true if the tag added was new, false if it already existed

Thumbnail getThumbnail(int $maximumWidth = null, int $maximumHeight = null, string $ratioMode = ImageInterface::RATIOMODE_INSET, bool $allowUpScaling = null)

Returns a thumbnail of this asset

If the maximum width / height is not specified or exceeds the original asset's dimensions, the width / height of the original asset is used.

Parameters

int $maximumWidth

The thumbnail's maximum width in pixels

int $maximumHeight

The thumbnail's maximum height in pixels

string $ratioMode

Whether the resulting image should be cropped if both edge's sizes are supplied that would hurt the aspect ratio

bool $allowUpScaling

Whether the resulting image should be upscaled

Return Value

Thumbnail

Exceptions

Exception
Exception

mixed addThumbnail(Thumbnail $thumbnail)

An internal method which adds a thumbnail which was generated by the ThumbnailService.

Parameters

Thumbnail $thumbnail

Return Value

mixed

See also

getThumbnail()

void refresh()

Refreshes this image variant: according to the added adjustments, a new image is rendered and stored as this image variant's resource.

Return Value

void

Exceptions

Exception
ImageFileException
InvalidConfigurationException

See also

getResource()

void setTags(Collection $tags)

Set the tags assigned to this asset

Parameters

Collection $tags

Return Value

void

bool removeTag(Tag $tag)

Remove a single tag from this asset

Parameters

Tag $tag

Return Value

bool

Collection getAssetCollections()

Return the asset collections this asset is included in

Return Value

Collection

void setAssetCollections(Collection $assetCollections)

Set the asset collections that include this asset

Parameters

Collection $assetCollections

Return Value

void

void setAssetSourceIdentifier(string $assetSourceIdentifier)

Set the asset source identifier for this asset

This is an internal method which allows Neos / Flow to keep track of assets which were imported from external asset sources.

Parameters

string $assetSourceIdentifier

Return Value

void

string|null getAssetSourceIdentifier()

No description

Return Value

string|null

AssetProxyInterface|null getAssetProxy()

No description

Return Value

AssetProxyInterface|null

bool isInUse()

Returns true if the asset is still in use.

Return Value

bool

int getUsageCount()

Returns the number of times the asset is in use.

Return Value

int

int getWidth()

Width of the image in pixels

Return Value

int

int getHeight()

Height of the image in pixels

Return Value

int

bool hasDimensions()

Does the asset have dimensions

Return Value

bool

float getAspectRatio(bool $respectOrientation = false)

Edge / aspect ratio of the image

Parameters

bool $respectOrientation

If false (the default), orientation is disregarded and always a value >= 1 is returned (like usual in "4 / 3" or "16 / 9")

Return Value

float

string getOrientation()

Orientation of this image, i.e. portrait, landscape or square

Return Value

string

One of this interface's ORIENTATION_* constants.

bool isOrientationSquare()

Whether this image is square aspect ratio and therefore has a square orientation

Return Value

bool

bool isOrientationLandscape()

Whether this image is in landscape orientation

Return Value

bool

bool isOrientationPortrait()

Whether this image is in portrait orientation

Return Value

bool

AssetInterface getOriginalAsset()

Returns the original image this variant is based on

Return Value

AssetInterface

void setName(string $name)

Sets a name which can be used for identifying this variant

Parameters

string $name

Return Value

void

string getName()

Returns the name

Return Value

string

void addVariant(ImageVariant $variant)

Adding variants to variants is not supported.

Parameters

ImageVariant $variant

Return Value

void

array getVariants()

Retrieving variants from variants is not supported (no-operation)

Return Value

array

void setPresetIdentifier(string $presetIdentifier)

Sets the identifier of the image variant preset which created this variant (if any)

Parameters

string $presetIdentifier

For example: 'Acme.Demo:Preset1'

Return Value

void

string|null getPresetIdentifier()

Returns the identifier of the image variant preset which created this variant (if any)

Return Value

string|null

void setPresetVariantName(string $presetVariantName)

No description

Parameters

string $presetVariantName

Return Value

void

string|null getPresetVariantName()

No description

Return Value

string|null

void addAdjustment(ImageAdjustmentInterface $adjustment)

Adds the given adjustment to the list of adjustments applied to this image variant.

If an adjustment of the given type already exists, the existing one will be overridden by the new one.

Parameters

ImageAdjustmentInterface $adjustment

The adjustment to apply

Return Value

void

Exceptions

Exception
ImageFileException
InvalidConfigurationException
Exception

void addAdjustments(array $adjustments)

Adds the given adjustments to the list of adjustments applied to this image variant.

If an adjustment of one of the given types already exists, the existing one will be overridden by the new one.

Parameters

array $adjustments

Return Value

void

Exceptions

Exception
ImageFileException
InvalidConfigurationException
Exception

protected void applyAdjustment(ImageAdjustmentInterface $adjustment)

Apply the given adjustment to the image variant.

If an adjustment of the given type already exists, the existing one will be overridden by the new one.

Parameters

ImageAdjustmentInterface $adjustment

Return Value

void

Exceptions

Exception

Collection getAdjustments()

No description

Return Value

Collection

protected void renderResource()

Tells the ImageService to render the resource of this ImageVariant according to the existing adjustments.

Return Value

void

Exceptions

InvalidConfigurationException
Exception
ImageFileException