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
3.7.63

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 config3:phpMaxMemoryLimit (opens new window) config setting, then try again.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# cleanImage()

Cleans an image by its path, clearing embedded potentially malicious embedded code.

View source (opens new window)

Arguments

Throws

# getCanUseImagick()

Returns whether Imagick is installed and meets version requirements

View source (opens new window)

Returns

boolean (opens new window)

# getExifData()

Get EXIF metadata for a file by it's path.

View source (opens new window)

Arguments

Returns

array (opens new window), null (opens new window)

# getImageMagickApiVersion()

Returns the installed ImageMagick API version.

View source (opens new window)

Returns

string (opens new window)

Throws

# getIsGd()

Returns whether image manipulations will be performed using GD or not.

View source (opens new window)

Returns

boolean (opens new window), null (opens new window)

# getIsImagick()

Returns whether image manipulations will be performed using Imagick or not.

View source (opens new window)

Returns

boolean (opens new window)

# getSupportedImageFormats()

Returns a list of all supported image formats.

View source (opens new window)

Returns

array (opens new window)

# getSupportsAvif()

Returns whether the AVIF image format is supported.

View source (opens new window)

Returns

boolean (opens new window)

# getSupportsHeic()

Since
3.7.63

Returns whether the HEIC/HEIF image format is supported.

View source (opens new window)

Returns

boolean (opens new window)

# getSupportsWebP()

Returns whether the WebP image format is supported.

View source (opens new window)

Returns

boolean (opens new window)

# getVersion()

Returns the version of the image driver.

View source (opens new window)

Returns

string (opens new window)

# 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

Returns

craft\base\Image

# rotateImageByExifData()

Rotate image according to it's EXIF data.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# stripOrientationFromExifData()

Strip orientation from EXIF data for an image at a path.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# Constants

Constant Description
DRIVER_GD
DRIVER_IMAGICK
MINIMUM_IMAGICK_VERSION