Images

Type
Class
Namespace
craft\services
Inherits
craft\services\Images » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0.0

Service for image operations.

An instance of the Images service is globally accessible in Craft via Craft::$app->images.

View source

Public Properties

PropertyDescription
behaviorsyii\base\Behavior – List of behaviors attached to this component
canUseImagickboolean
imageMagickApiVersionstring
isGdboolean, null
isImagickboolean
supportedImageFormatsarray – Image formats that can be manipulated.
version

canUseImagick

Type
boolean
Access
Read-only

View source

imageMagickApiVersion

Type
string
Access
Read-only

View source

isGd

Type
boolean, null
Access
Read-only

View source

isImagick

Type
boolean
Access
Read-only

View source

supportedImageFormats

Type
array
Access
Read-only

Image formats that can be manipulated.

View source

version

Type

:

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 an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to 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.
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.
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 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

getVersion()

Returns the version of the image driver.

View source

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