Skip to content

Raster ​

Type
Class
Namespace
craft\image
Inherits
craft\image\Raster » craft\base\Image » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0.0

Raster class is used for raster image manipulations.

View source

Public Properties ​

PropertyDescription
extensionstring
heightinteger
imagineImage\Imagine\Image\AbstractImage, null
interlacestring
isTransparentboolean – Whether the image is transparent
qualityinteger
widthinteger

extension ​

Type
string
Default value
null
Access
Read-only

View source

height ​

Type
integer
Default value
null
Access
Read-only

View source

imagineImage ​

Type
\Imagine\Image\AbstractImage, null
Default value
null
Access
Read-only

View source

interlace ​

Type
string
Default value
null
Access
Write-only

View source

quality ​

Type
integer
Default value
null
Access
Write-only

View source

width ​

Type
integer
Default value
null
Access
Read-only

View source

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__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.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
crop()Crops the image to the specified coordinates.
disableAnimation()Disable animation if this is an animated image.
flipHorizontally()Flips the image horizontally.
flipVertically()Flips the image vertically.
getExifMetadata()Returns EXIF metadata for a file by its path.
getExtension()Returns the file extension.
getHeight()Returns the height of the image.
getImagineImage()Return the Imagine Image instance
getIsTransparent()Returns whether the image is transparent.
getTextBox()Returns the bounding text box for a text string and an angle
getWidth()Returns the width of the image.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
loadFromSVG()Loads an image from an SVG string.
loadImage()Loads an image from a file system path.
resize()Resizes the image.
rotate()Rotates the image by the given degrees.
saveAs()Saves the image to the target path.
scaleAndCrop()Scale and crop image to exactly fit the specified size.
scaleToFit()Scale the image to fit within the specified size.
setFontProperties()Sets properties for text drawing on the image.
setInterlace()Sets the interlace setting.
setQuality()Sets the image quality.
writeText()Writes text on an image.

__construct() ​

Constructor.

The default implementation does two things:

  • Initializes the object with the given configuration $config.
  • Call init().

If this method is overridden in a child class, it is recommended that

  • the last parameter of the constructor is a configuration array, like $config here.
  • call the parent implementation at the end of the constructor.

View source

Arguments ​

  • $config (array) – Name-value pairs that will be used to initialize the object properties

crop() ​

Crops the image to the specified coordinates.

View source

Arguments ​

Returns ​

static – Self reference

disableAnimation() ​

Disable animation if this is an animated image.

View source

Returns ​

$this

flipHorizontally() ​

Flips the image horizontally.

View source

Returns ​

static – Self reference

flipVertically() ​

Flips the image vertically.

View source

Returns ​

static – Self reference

getExifMetadata() ​

Returns EXIF metadata for a file by its path.

View source

Arguments ​

Returns ​

array

getExtension() ​

Returns the file extension.

View source

Returns ​

string

getHeight() ​

Returns the height of the image.

View source

Returns ​

integer

getImagineImage() ​

Return the Imagine Image instance

View source

Returns ​

\Imagine\Image\AbstractImage, null

getIsTransparent() ​

Returns whether the image is transparent.

View source

Returns ​

boolean

getTextBox() ​

Returns the bounding text box for a text string and an angle

View source

Arguments ​

Returns ​

\Imagine\Image\BoxInterface

Throws ​

getWidth() ​

Returns the width of the image.

View source

Returns ​

integer

loadFromSVG() ​

Loads an image from an SVG string.

View source

Arguments ​

Returns ​

static – Self reference

Throws ​

loadImage() ​

Loads an image from a file system path.

View source

Arguments ​

Returns ​

static, craft\image\Svg – Self reference

Throws ​

resize() ​

Resizes the image.

View source

Arguments ​

  • $targetWidth (integer, null) – The target width
  • $targetHeight (integer, null) – The target height. Defaults to $targetWidth if omitted, creating a square.

Returns ​

static – Self reference

rotate() ​

Rotates the image by the given degrees.

View source

Arguments ​

Returns ​

static – Self reference

saveAs() ​

Saves the image to the target path.

View source

Arguments ​

Returns ​

boolean

Throws ​

scaleAndCrop() ​

Scale and crop image to exactly fit the specified size.

View source

Arguments ​

Returns ​

static – Self reference

scaleToFit() ​

Scale the image to fit within the specified size.

View source

Arguments ​

Returns ​

static – Self reference

setFontProperties() ​

Sets properties for text drawing on the image.

View source

Arguments ​

  • $fontFile (string) – Path to the font file on server
  • $size (integer) – Font size to use
  • $color (string) – Font color to use in hex format

setInterlace() ​

Sets the interlace setting.

View source

Arguments ​

Returns ​

static – Self reference

setQuality() ​

Sets the image quality.

View source

Arguments ​

Returns ​

static – Self reference

writeText() ​

Writes text on an image.

View source

Arguments ​

Throws ​

Protected Methods ​

MethodDescription
normalizeDimensions()Normalizes the given dimensions. If width or height is set to 'AUTO', we calculate the missing dimension.