Images ​
- Type
- Class
- Namespace
- craft\services
- Inherits
- craft\services\Images » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 3.0.0
Images service.
An instance of the service is available via Craft::$app->getImages().
Public Properties ​
| Property | Description |
|---|---|
| behaviors | yii\base\Behavior – List of behaviors attached to this component. |
| canUseImagick | boolean |
| imageMagickApiVersion | string |
| isGd | boolean – Whether image manipulations will be performed using GD or not |
| isImagick | boolean – Whether image manipulations will be performed using Imagick or not |
| supportedImageFormats | array – Image formats that can be manipulated. |
| supportsAvif | boolean |
| supportsHeic | boolean |
| supportsWebP | boolean |
| version | string |
canUseImagick ​
- Type
- boolean
- Default value
null- Access
- Read-only
imageMagickApiVersion ​
- Type
- string
- Default value
null- Access
- Read-only
isGd ​
- Type
- boolean
- Default value
null
Whether image manipulations will be performed using GD or not
isImagick ​
- Type
- boolean
- Default value
null
Whether image manipulations will be performed using Imagick or not
supportedImageFormats ​
- Type
- array
- Default value
[ 'jpg', 'jpeg', 'gif', 'png', ]
Image formats that can be manipulated.
supportsAvif ​
- Type
- boolean
- Default value
null- Access
- Read-only
supportsHeic ​
- Type
- boolean
- Default value
null- Access
- Read-only
- Since
- 4.3.6
supportsWebP ​
- Type
- boolean
- Default value
null- Access
- Read-only
version ​
- Type
- string
- Default value
null- Access
- Read-only
Public Methods ​
| Method | Description |
|---|---|
| __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 a component property. |
| __isset() | Checks if a property is set, i.e. defined and not null. |
| __set() | Sets the value of a component property. |
| __unset() | Sets a component property to be 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. |
| checkMemoryForImage() | Determines if there is enough memory to process this image. |
| className() | Returns the fully qualified name of this class. |
| cleanImage() | Cleans an image by its path, clearing embedded potentially malicious embedded code. |
| detachBehavior() | Detaches a behavior from the component. |
| detachBehaviors() | Detaches all behaviors from the component. |
| ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. |
| getBehavior() | Returns the named behavior object. |
| getBehaviors() | Returns all behaviors attached to this component. |
| getCanUseImagick() | Returns whether Imagick is installed and meets version requirements |
| getExifData() | Get EXIF metadata for a file by it's path. |
| getImageMagickApiVersion() | Returns the installed ImageMagick API version. |
| getIsGd() | Returns whether image manipulations will be performed using GD or not. |
| getIsImagick() | Returns whether image manipulations will be performed using Imagick or not. |
| getSupportedImageFormats() | Returns a list of all supported image formats. |
| getSupportsAvif() | Returns whether the AVIF image format is supported. |
| getSupportsHeic() | Returns whether the HEIC/HEIF image format is supported. |
| getSupportsWebP() | Returns whether the WebP image format is supported. |
| getVersion() | Returns the version of the image driver. |
| 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 for this component. |
| init() | Decide on the image driver being used. |
| loadImage() | Loads an image from a file system path. |
| off() | Detaches an existing event handler from this component. |
| on() | Attaches an event handler to an event. |
| rotateImageByExifData() | Rotate image according to it's EXIF data. |
| stripOrientationFromExifData() | Strip orientation from EXIF data for an image at a path. |
| trigger() | Triggers an event. |
checkMemoryForImage() ​
Determines if there is enough memory to process this image.
The code was adapted from http://www.php.net/manual/en/function.imagecreatefromjpeg.php#64155. It will first attempt to do it with available memory. If that fails, Craft will bump the memory to amount defined by the config4:phpMaxMemoryLimit config setting, then try again.
Arguments ​
$filePath(string) – The path to the image file.$toTheMax(boolean) – If set to true, will set the PHP memory to the config setting phpMaxMemoryLimit.
Returns ​
cleanImage() ​
Cleans an image by its path, clearing embedded potentially malicious embedded code.
Arguments ​
$filePath(string)
Throws ​
- yii\base\Exception
if $filePath is a malformed SVG image
getCanUseImagick() ​
Returns whether Imagick is installed and meets version requirements
Returns ​
getExifData() ​
Get EXIF metadata for a file by it's path.
Arguments ​
$filePath(string)
Returns ​
getImageMagickApiVersion() ​
Returns the installed ImageMagick API version.
Returns ​
Throws ​
- yii\base\Exception
if the Imagick extension isn’t installed
getIsGd() ​
Returns whether image manipulations will be performed using GD or not.
Returns ​
getIsImagick() ​
Returns whether image manipulations will be performed using Imagick or not.
Returns ​
getSupportedImageFormats() ​
Returns a list of all supported image formats.
Returns ​
getSupportsAvif() ​
Returns whether the AVIF image format is supported.
Returns ​
getSupportsHeic() ​
- Since
- 4.3.6
Returns whether the HEIC/HEIF image format is supported.
Returns ​
getSupportsWebP() ​
Returns whether the WebP image format is supported.
Returns ​
getVersion() ​
Returns the version of the image driver.
Returns ​
init() ​
Decide on the image driver being used.
loadImage() ​
Loads an image from a file system path.
Arguments ​
$path(string)$rasterize(boolean) – Whether the image should be rasterized if it's an SVG$svgSize(integer) – The size SVG should be scaled up to, if rasterized
Returns ​
rotateImageByExifData() ​
Rotate image according to it's EXIF data.
Arguments ​
$filePath(string)
Returns ​
stripOrientationFromExifData() ​
Strip orientation from EXIF data for an image at a path.
Arguments ​
$filePath(string)
Returns ​
Constants ​
| Constant | Description |
|---|---|
DRIVER_GD | |
DRIVER_IMAGICK | |
MINIMUM_IMAGICK_VERSION |