Skip to content

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->images.

View source

Public Properties ​

PropertyDescription
behaviorsyii\base\Behavior – List of behaviors attached to this component.
canUseImagickboolean
imageMagickApiVersionstring
isGdboolean – Whether image manipulations will be performed using GD or not
isImagickboolean – Whether image manipulations will be performed using Imagick or not
supportedImageFormatsarray – Image formats that can be manipulated.
supportsAvifboolean
supportsHeicboolean
supportsWebPboolean
versionstring

canUseImagick ​

Type
boolean
Default value
null
Access
Read-only

View source

imageMagickApiVersion ​

Type
string
Default value
null
Access
Read-only

View source

isGd ​

Type
boolean
Default value
null

Whether image manipulations will be performed using GD or not

View source

isImagick ​

Type
boolean
Default value
null

Whether image manipulations will be performed using Imagick or not

View source

supportedImageFormats ​

Type
array
Default value
[ 'jpg', 'jpeg', 'gif', 'png', ]

Image formats that can be manipulated.

View source

supportsAvif ​

Type
boolean
Default value
null
Access
Read-only

View source

supportsHeic ​

Type
boolean
Default value
null
Access
Read-only
Since
3.7.63

View source

supportsWebP ​

Type
boolean
Default value
null
Access
Read-only

View source

version ​

Type
string
Default value
null
Access
Read-only

View source

Public Methods ​

MethodDescription
__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 config3:phpMaxMemoryLimit config setting, then try again.

View source

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 ​

boolean

cleanImage() ​

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

View source

Arguments ​

Throws ​

getCanUseImagick() ​

Returns whether Imagick is installed and meets version requirements

View source

Returns ​

boolean

getExifData() ​

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

View source

Arguments ​

Returns ​

array, null

getImageMagickApiVersion() ​

Returns the installed ImageMagick API version.

View source

Returns ​

string

Throws ​

getIsGd() ​

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

View source

Returns ​

boolean, null

getIsImagick() ​

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

View source

Returns ​

boolean

getSupportedImageFormats() ​

Returns a list of all supported image formats.

View source

Returns ​

array

getSupportsAvif() ​

Returns whether the AVIF image format is supported.

View source

Returns ​

boolean

getSupportsHeic() ​

Since
3.7.63

Returns whether the HEIC/HEIF image format is supported.

View source

Returns ​

boolean

getSupportsWebP() ​

Returns whether the WebP image format is supported.

View source

Returns ​

boolean

getVersion() ​

Returns the version of the image driver.

View source

Returns ​

string

init() ​

Decide on the image driver being used.

View source

loadImage() ​

Loads an image from a file system path.

View source

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 ​

craft\base\Image

rotateImageByExifData() ​

Rotate image according to it's EXIF data.

View source

Arguments ​

Returns ​

boolean

stripOrientationFromExifData() ​

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

View source

Arguments ​

Returns ​

boolean

Constants ​

ConstantDescription
DRIVER_GD
DRIVER_IMAGICK
MINIMUM_IMAGICK_VERSION