Images
- Type
- Class
- Namespace
- craft\services
- Inherits
- craft\services\Images » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
- Implements
- yii\base\Configurable (opens new window)
- Since
- 3.0.0
Images service.
An instance of the service is available via Craft::$app->images
.
View source (opens new window)
# Public Properties
Property | Description |
---|---|
behaviors (opens new window) | yii\base\Behavior (opens new window) – List of behaviors attached to this component. |
canUseImagick | boolean (opens new window) |
imageMagickApiVersion | string (opens new window) |
isGd | boolean (opens new window) – Whether image manipulations will be performed using GD or not |
isImagick | boolean (opens new window) – Whether image manipulations will be performed using Imagick or not |
supportedImageFormats | array (opens new window) – Image formats that can be manipulated. |
supportsAvif | boolean (opens new window) |
supportsHeic | boolean (opens new window) |
supportsWebP | boolean (opens new window) |
version | string (opens new window) |
# canUseImagick
- Type
- boolean (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# imageMagickApiVersion
- Type
- string (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# isGd
- Type
- boolean (opens new window)
- Default value
null
Whether image manipulations will be performed using GD or not
View source (opens new window)
# isImagick
- Type
- boolean (opens new window)
- Default value
null
Whether image manipulations will be performed using Imagick or not
View source (opens new window)
# supportedImageFormats
- Type
- array (opens new window)
- Default value
[ 'jpg', 'jpeg', 'gif', 'png', ]
Image formats that can be manipulated.
View source (opens new window)
# supportsAvif
- Type
- boolean (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# supportsHeic
- Type
- boolean (opens new window)
- Default value
null
- Access
- Read-only
- Since
- 4.3.6
View source (opens new window)
# supportsWebP
- Type
- boolean (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# version
- Type
- string (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__clone() (opens new window) | This method is called after the object is created by cloning an existing one. |
__construct() (opens new window) | Constructor. |
__get() (opens new window) | Returns the value of a component property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__set() (opens new window) | Sets the value of a component property. |
__unset() (opens new window) | Sets a component property to be null. |
attachBehavior() (opens new window) | Attaches a behavior to this component. |
attachBehaviors() (opens new window) | Attaches a list of behaviors to the component. |
behaviors() (opens new window) | Returns a list of behaviors that this component should behave as. |
canGetProperty() (opens new window) | Returns a value indicating whether a property can be read. |
canSetProperty() (opens new window) | Returns a value indicating whether a property can be set. |
checkMemoryForImage() | Determines if there is enough memory to process this image. |
className() (opens new window) | Returns the fully qualified name of this class. |
cleanImage() | Cleans an image by its path, clearing embedded potentially malicious embedded code. |
detachBehavior() (opens new window) | Detaches a behavior from the component. |
detachBehaviors() (opens new window) | Detaches all behaviors from the component. |
ensureBehaviors() (opens new window) | Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component. |
getBehavior() (opens new window) | Returns the named behavior object. |
getBehaviors() (opens new window) | 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() (opens new window) | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() (opens new window) | Returns a value indicating whether a method is defined. |
hasProperty() (opens new window) | 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() (opens new window) | Detaches an existing event handler from this component. |
on() (opens new window) | 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() (opens new window) | 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 (opens new window) config setting, then try again.
View source (opens new window)
Arguments
$filePath
(string (opens new window)) – The path to the image file.$toTheMax
(boolean (opens new window)) – 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.
View source (opens new window)
Arguments
$filePath
(string (opens new window))
Throws
- yii\base\Exception (opens new window)
if $filePath is a malformed SVG image
# getCanUseImagick()
Returns whether Imagick is installed and meets version requirements
View source (opens new window)
Returns
# getExifData()
Get EXIF metadata for a file by it's path.
View source (opens new window)
Arguments
$filePath
(string (opens new window))
Returns
array (opens new window), null (opens new window)
# getImageMagickApiVersion()
Returns the installed ImageMagick API version.
View source (opens new window)
Returns
Throws
- yii\base\Exception (opens new window)
if the Imagick extension isn’t installed
# getIsGd()
Returns whether image manipulations will be performed using GD or not.
View source (opens new window)
Returns
# getIsImagick()
Returns whether image manipulations will be performed using Imagick or not.
View source (opens new window)
Returns
# getSupportedImageFormats()
Returns a list of all supported image formats.
View source (opens new window)
Returns
# getSupportsAvif()
Returns whether the AVIF image format is supported.
View source (opens new window)
Returns
# getSupportsHeic()
- Since
- 4.3.6
Returns whether the HEIC/HEIF image format is supported.
View source (opens new window)
Returns
# getSupportsWebP()
Returns whether the WebP image format is supported.
View source (opens new window)
Returns
# getVersion()
Returns the version of the image driver.
View source (opens new window)
Returns
# init()
Decide on the image driver being used.
View source (opens new window)
# loadImage()
Loads an image from a file system path.
View source (opens new window)
Arguments
$path
(string (opens new window))$rasterize
(boolean (opens new window)) – Whether the image should be rasterized if it's an SVG$svgSize
(integer (opens new window)) – The size SVG should be scaled up to, if rasterized
Returns
# rotateImageByExifData()
Rotate image according to it's EXIF data.
View source (opens new window)
Arguments
$filePath
(string (opens new window))
Returns
# stripOrientationFromExifData()
Strip orientation from EXIF data for an image at a path.
View source (opens new window)
Arguments
$filePath
(string (opens new window))
Returns
# Constants
Constant | Description |
---|---|
DRIVER_GD | |
DRIVER_IMAGICK | |
MINIMUM_IMAGICK_VERSION |