SilverStripe\Assets\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()
Other manipulations that do not create variants:
- LazyLoad()
Synopsis
trait ImageManipulation
{
- // members
- protected Image_Backend $imageBackend;
- protected bool $allowGeneration = true;
- private static bool $force_resample = false;
- private static integer $strip_thumbnail_width = 50;
- private static integer $strip_thumbnail_height = 50;
- private static integer $cms_thumbnail_width = 100;
- private static integer $cms_thumbnail_height = 100;
- private static integer $asset_preview_width = 930;
- private static integer $asset_preview_height = 336;
- // methods
- public $this setAllowGeneration()
- public bool getAllowGeneration()
- public DBFile existingOnly()
- public abstract string getString()
- public abstract resource getStream()
- public abstract string getURL()
- public abstract string getAbsoluteURL()
- public abstract array|null getMetaData()
- public abstract string getMimeType()
- public abstract int getAbsoluteSize()
- public abstract bool exists()
- public abstract string getFilename()
- public abstract string getHash()
- public abstract string getVariant()
- public abstract bool getIsImage()
- public AssetContainer Pad()
- public AssetContainer Resampled()
- public void updateURL()
- public AssetContainer ResizedImage()
- public AssetContainer Fit()
- public AssetContainer FitMax()
- public AssetContainer ScaleWidth()
- public AssetContainer ScaleMaxWidth()
- public AssetContainer ScaleHeight()
- public AssetContainer ScaleMaxHeight()
- public AssetContainer CropWidth()
- public AssetContainer CropHeight()
- public AssetContainer FillMax()
- public AssetContainer Fill()
- public AssetContainer Quality()
- public DBFile|DBHTMLText CMSThumbnail()
- public AssetContainer|DBHTMLText StripThumbnail()
- public AssetContainer|DBHTMLText PreviewThumbnail()
- public AssetContainer Thumbnail()
- public AssetContainer|DBHTMLText ThumbnailIcon()
- public DBHTMLText IconTag()
- public string ThumbnailURL()
- public string getIcon()
- public Image_Backend getImageBackend()
- public $this setImageBackend()
- public int getWidth()
- public int getHeight()
- public int getOrientation()
- public boolean isSize()
- public boolean isWidth()
- public boolean isHeight()
- public DBFile manipulateImage()
- public DBFile manipulate()
- public string variantName()
- public array|null variantParts()
- protected int castDimension()
- private AssetContainer copyImageBackend()
- public AssetContainer setAttribute()
- public void initAttributes()
- protected void getDefaultAttributes()
- public array getAttributes()
- public bool IsLazyLoaded()
- public AssetContainer LazyLoad()
Hierarchy
Uses
- SilverStripe\View\AttributesHTML
Used by
Members
private
- $asset_preview_height
—
int
The height of an image preview in the Asset section - $asset_preview_width
—
int
The width of an image preview in the Asset section - $cms_thumbnail_height
—
int
The height of an image thumbnail in the CMS. - $cms_thumbnail_width
—
int
The width of an image thumbnail in the CMS. - $force_resample
—
SilverStripe\Assets\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_height — int
- $strip_thumbnail_width — int
protected
- $allowGeneration
—
SilverStripe\Assets\bool
If image resizes are allowed - $imageBackend — SilverStripe\Assets\Image_Backend
Methods
private
- copyImageBackend() — Create an equivalent DBFile object
protected
- castDimension() — Validate a width or size is valid and casts it to integer
- getDefaultAttributes()
public
- CMSThumbnail() — Default CMS thumbnail
- CropHeight() — Crop image on Y axis if it exceeds specified height. Retain width.
- CropWidth() — Crop image on X axis if it exceeds specified width. Retain height.
- Fill() — Resize and crop image to fill specified dimensions.
- FillMax() — 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.
- Fit() — Scale image proportionally to fit within the specified bounds
- FitMax() — Proportionally scale down this image if it is wider or taller than the specified dimensions.
- IconTag() — Get HTML for img containing the icon for this file
- IsLazyLoaded() — Determine whether the image should be lazy loaded
- LazyLoad() — Set the lazy loading state for this Image
- Pad() — Fit image to specified dimensions and fill leftover space with a solid colour (default white). Use in templates with $Pad.
- PreviewThumbnail() — Get preview for this file
- Quality() — Set the quality of the resampled image
- Resampled() — Forces the image to be resampled, if possible
- ResizedImage() — Generate a resized copy of this image with the given width & height.
- ScaleHeight() — Scale image proportionally by height. Use in templates with $ScaleHeight.
- ScaleMaxHeight() — Proportionally scale down this image if it is taller than the specified height.
- ScaleMaxWidth() — Proportionally scale down this image if it is wider than the specified width.
- ScaleWidth() — Scale image proportionally by width. Use in templates with $ScaleWidth.
- StripThumbnail() — Generates a thumbnail for use in the gridfield view
- Thumbnail() — Default thumbnail generation for Images
- ThumbnailIcon() — Thubnail generation for all file types.
- ThumbnailURL() — Get URL to thumbnail of the given size.
- existingOnly() — Return clone of self which promises to only return existing thumbnails
- exists() — Determine if this container has a valid value
- getAbsoluteSize() — Return file size in bytes.
- getAbsoluteURL()
- getAllowGeneration() — Check if resizes are allowed
- getAttributes() — Allows customization through an 'updateAttributes' hook on the base class.
- getFilename() — Get value of filename
- getHash() — Get value of hash
- getHeight() — Get the height of this image.
- getIcon() — Return the relative URL of an icon for the file type, based on the {@link appCategory()} value.
- getImageBackend() — Get Image_Backend instance for this image
- getIsImage() — Determine if a valid non-empty image exists behind this asset
- getMetaData() — Get metadata for this file
- getMimeType() — Get mime type
- getOrientation() — Get the orientation of this image.
- getStream()
- getString()
- getURL()
- getVariant() — Get value of variant
- getWidth() — Get the width of this image.
- initAttributes() — Initialise the attirbutes on this object. Should only be called imiditely after intialising the object.
- isHeight() — Determine if this image is of the specified width
- isSize() — Determine if this image is of the specified size
- isWidth() — Determine if this image is of the specified width
- manipulate() — Generate a new DBFile instance using the given callback if it hasn't been created yet, or return the existing one if it has.
- manipulateImage() — Wrapper for manipulate that passes in and stores Image_Backend objects instead of tuples
- setAllowGeneration() — Set whether image resizes are allowed
- setAttribute() — Add a HTML attribute when rendering this object. This method is immutable, it will return you a copy of the original object.
- setImageBackend()
- updateURL() — Update the url to point to a resampled version if forcing
- variantName() — Name a variant based on a format with arbitrary parameters
- variantParts() — Reverses {@link variantName()}.