ImageManipulation
trait ImageManipulation
Provides image manipulation functionality.
Provides limited thumbnail generation functionality for non-image files. Should only be applied to implementors of AssetContainer
Allows raw images to be resampled via Resampled()
Image scaling manipluations, including: - Fit() - FitMax() - ScaleWidth() - ScaleMaxWidth() - ScaleHeight() - ScaleMaxHeight() - ResizedImage()
Image cropping manipulations, including: - CropHeight() - CropWidth() - Fill() - FillMax()
Thumbnail generation methods including: - Icon() - CMSThumbnail()
Config options
force_resample | bool | Force all images to resample in all cases Off by default, as this can be resource intensive to apply to multiple images simultaneously. | |
strip_thumbnail_width | int | ||
strip_thumbnail_height | int | ||
cms_thumbnail_width | int | The width of an image thumbnail in the CMS. | |
cms_thumbnail_height | int | The height of an image thumbnail in the CMS. | |
asset_preview_width | int | The width of an image preview in the Asset section | |
asset_preview_height | int | The height of an image preview in the Asset section |
Methods
Set whether image resizes are allowed
Check if resizes are allowed
Return clone of self which promises to only return existing thumbnails
No description
No description
No description
No description
Get metadata for this file
Get mime type
Return file size in bytes.
Determine if this container has a valid value
Get value of filename
Get value of hash
Get value of variant
Determine if a valid non-empty image exists behind this asset
Fit image to specified dimensions and fill leftover space with a solid colour (default white). Use in templates with $Pad.
Forces the image to be resampled, if possible
Update the url to point to a resampled version if forcing
Generate a resized copy of this image with the given width & height.
Scale image proportionally to fit within the specified bounds
Proportionally scale down this image if it is wider or taller than the specified dimensions.
Scale image proportionally by width. Use in templates with $ScaleWidth.
Proportionally scale down this image if it is wider than the specified width.
Scale image proportionally by height. Use in templates with $ScaleHeight.
Proportionally scale down this image if it is taller than the specified height.
Crop image on X axis if it exceeds specified width. Retain height.
Crop image on Y axis if it exceeds specified height. Retain width.
Crop this image to the aspect ratio defined by the specified width and height, then scale down the image to those dimensions if it exceeds them.
Resize and crop image to fill specified dimensions.
Set the quality of the resampled image
Default CMS thumbnail
Generates a thumbnail for use in the gridfield view
Get preview for this file
Default thumbnail generation for Images
Thumbnail generation for all file types.
Get HTML for img containing the icon for this file
Get URL to thumbnail of the given size.
Return the relative URL of an icon for the file type, based on the {@link appCategory()} value.
Get Image_Backend instance for this image
Get the width of this image.
Get the height of this image.
Get the orientation of this image.
Determine if this image is of the specified size
Determine if this image is of the specified width
Determine if this image is of the specified width
Wrapper for manipulate that passes in and stores Image_Backend objects instead of tuples
Generate a new DBFile instance using the given callback if it hasn't been created yet, or return the existing one if it has.
Name a variant based on a format with arbitrary parameters
Reverses {@link variantName()}.
Details
at line 67
$this
setAllowGeneration(bool $allow)
Set whether image resizes are allowed
at line 78
bool
getAllowGeneration()
Check if resizes are allowed
at line 88
DBFile
existingOnly()
Return clone of self which promises to only return existing thumbnails
at line 104
abstract string
getString()
at line 109
abstract resource
getStream()
at line 115
abstract string
getURL(bool $grant = true)
at line 120
abstract string
getAbsoluteURL()
at line 127
abstract array|null
getMetaData()
Get metadata for this file
at line 134
abstract string
getMimeType()
Get mime type
at line 141
abstract int
getAbsoluteSize()
Return file size in bytes.
at line 148
abstract bool
exists()
Determine if this container has a valid value
at line 155
abstract string
getFilename()
Get value of filename
at line 162
abstract string
getHash()
Get value of hash
at line 169
abstract string
getVariant()
Get value of variant
at line 176
abstract bool
getIsImage()
Determine if a valid non-empty image exists behind this asset
at line 241
AssetContainer
Pad(int $width, int $height, string $backgroundColor = 'FFFFFF', int $transparencyPercent)
Fit image to specified dimensions and fill leftover space with a solid colour (default white). Use in templates with $Pad.
at line 262
AssetContainer
Resampled()
Forces the image to be resampled, if possible
at line 285
updateURL(string $url)
Update the url to point to a resampled version if forcing
at line 314
AssetContainer
ResizedImage(int $width, int $height)
Generate a resized copy of this image with the given width & height.
This can be used in templates with $ResizedImage but should be avoided, as it's the only image manipulation function which can skew an image.
at line 334
AssetContainer
Fit(int $width, int $height)
Scale image proportionally to fit within the specified bounds
at line 375
AssetContainer
FitMax(int $width, int $height)
Proportionally scale down this image if it is wider or taller than the specified dimensions.
Similar to Fit but without up-sampling. Use in templates with $FitMax.
at line 419
AssetContainer
ScaleWidth(int $width)
Scale image proportionally by width. Use in templates with $ScaleWidth.
at line 439
AssetContainer
ScaleMaxWidth(int $width)
Proportionally scale down this image if it is wider than the specified width.
Similar to ScaleWidth but without up-sampling. Use in templates with $ScaleMaxWidth.
at line 457
AssetContainer
ScaleHeight(int $height)
Scale image proportionally by height. Use in templates with $ScaleHeight.
at line 477
AssetContainer
ScaleMaxHeight(int $height)
Proportionally scale down this image if it is taller than the specified height.
Similar to ScaleHeight but without up-sampling. Use in templates with $ScaleMaxHeight.
at line 498
AssetContainer
CropWidth(int $width)
Crop image on X axis if it exceeds specified width. Retain height.
Use in templates with $CropWidth. Example: $Image.ScaleHeight(100).$CropWidth(100)
at line 520
AssetContainer
CropHeight(int $height)
Crop image on Y axis if it exceeds specified height. Retain width.
Use in templates with $CropHeight. Example: $Image.ScaleWidth(100).CropHeight(100)
at line 544
AssetContainer
FillMax(int $width, int $height)
Crop this image to the aspect ratio defined by the specified width and height, then scale down the image to those dimensions if it exceeds them.
Similar to Fill but without up-sampling. Use in templates with $FillMax.
at line 584
AssetContainer
Fill(int $width, int $height)
Resize and crop image to fill specified dimensions.
Use in templates with $Fill
at line 604
AssetContainer
Quality(int $quality)
Set the quality of the resampled image
at line 618
DBFile|DBHTMLText
CMSThumbnail()
Default CMS thumbnail
at line 630
AssetContainer|DBHTMLText
StripThumbnail()
Generates a thumbnail for use in the gridfield view
at line 642
AssetContainer|DBHTMLText
PreviewThumbnail()
Get preview for this file
at line 655
AssetContainer
Thumbnail(int $width, int $height)
Default thumbnail generation for Images
at line 669
AssetContainer|DBHTMLText
ThumbnailIcon(int $width, int $height)
Thumbnail generation for all file types.
Resizes images, but returns an icon <img />
tag if this is not a resizable image
at line 679
DBHTMLText
IconTag()
Get HTML for img containing the icon for this file
at line 698
string
ThumbnailURL(int $width, int $height)
Get URL to thumbnail of the given size.
May fallback to default icon
at line 714
string
getIcon()
Return the relative URL of an icon for the file type, based on the {@link appCategory()} value.
Images are searched for in "framework/images/app_icons/".
at line 726
Image_Backend
getImageBackend()
Get Image_Backend instance for this image
at line 751
$this
setImageBackend(Image_Backend $backend)
at line 762
int
getWidth()
Get the width of this image.
at line 776
int
getHeight()
Get the height of this image.
at line 790
int
getOrientation()
Get the orientation of this image.
at line 810
boolean
isSize(int $width, int $height)
Determine if this image is of the specified size
at line 821
boolean
isWidth(int $width)
Determine if this image is of the specified width
at line 833
boolean
isHeight(int $height)
Determine if this image is of the specified width
at line 847
DBFile
manipulateImage(string $variant, callable $callback)
Wrapper for manipulate that passes in and stores Image_Backend objects instead of tuples
at line 917
DBFile
manipulate(string $variant, callable $callback)
Generate a new DBFile instance using the given callback if it hasn't been created yet, or return the existing one if it has.
at line 994
string
variantName($format, $arg = null)
Name a variant based on a format with arbitrary parameters
at line 1013
array|null
variantParts($variantName)
Reverses {@link variantName()}.
The "format" part of a variant name is a method name on the owner of this trait. For legacy reasons, there's no delimiter between this part, and the encoded arguments. This means we have to use a whitelist of "known formats", based on methods available on the {@link Image} class as the "main" user of this trait. This class is commonly decorated with additional manipulation methods through {@link DataExtension}.