Raster

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

Raster class is used for raster image manipulations.

View source

Public Properties

$extension

Type
string
Access
Read-only

View source

Signature

public string getExtension ( )

$height

Type
integer
Access
Read-only

View source

Signature

public integer getHeight ( )

$imagineImage

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

View source

Signature

public \Imagine\Image\AbstractImage, null getImagineImage ( )

$interlace

Type
string
Access
Write-only

View source

Signature

public static setInterlace ( \craft\image\string $interlace )

$isTransparent

Type
boolean
Access
Read-only

View source

Signature

public boolean getIsTransparent ( )

$quality

Type
integer
Access
Write-only

View source

Signature

public static setQuality ( \craft\image\int $quality )

$width

Type
integer
Access
Read-only

View source

Signature

public integer getWidth ( )

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

Signature

public void __construct ( $config = [] )

crop()

Crops the image to the specified coordinates.

View source

Arguments

Returns

static – Self reference

Signature

public static crop ( \craft\image\int $x1, \craft\image\int $x2, \craft\image\int $y1, \craft\image\int $y2 )

flipHorizontally()

Flips the image horizontally.

View source

Returns

static – Self reference

Signature

public static flipHorizontally ( )

flipVertically()

Flips the image vertically.

View source

Returns

static – Self reference

Signature

public static flipVertically ( )

getExifMetadata()

Returns EXIF metadata for a file by its path.

View source

Arguments

Returns

array

Signature

public array getExifMetadata ( \craft\image\string $filePath )

getExtension()

Returns the file extension.

View source

Returns

string

Signature

public string getExtension ( )

getHeight()

Returns the height of the image.

View source

Returns

integer

Signature

public integer getHeight ( )

getImagineImage()

Return the Imagine Image instance

View source

Returns

\Imagine\Image\AbstractImage, null

Signature

public \Imagine\Image\AbstractImage, null getImagineImage ( )

getIsTransparent()

Returns whether the image is transparent.

View source

Returns

boolean

Signature

public boolean getIsTransparent ( )

getTextBox()

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

View source

Arguments

Returns

\Imagine\Image\BoxInterface

Throws

Signature

public \Imagine\Image\BoxInterface getTextBox ( \craft\image\string $text, \craft\image\int $angle = 0 )

getWidth()

Returns the width of the image.

View source

Returns

integer

Signature

public integer getWidth ( )

loadFromSVG()

Loads an image from an SVG string.

View source

Arguments

Returns

static – Self reference

Throws

Signature

public static loadFromSVG ( \craft\image\string $svgContent )

loadImage()

Loads an image from a file system path.

View source

Arguments

Returns

static, craft\image\Svg – Self reference

Throws

Signature

public static, craft\image\Svg loadImage ( \craft\image\string $path )

resize()

Resizes the image.

View source

Arguments

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

Returns

static – Self reference

Signature

public static resize ( \craft\image\int $targetWidth = null, \craft\image\int $targetHeight = null )

rotate()

Rotates the image by the given degrees.

View source

Arguments

Returns

static – Self reference

Signature

public static rotate ( \craft\image\float $degrees )

saveAs()

Saves the image to the target path.

View source

Arguments

Returns

boolean

Throws

Signature

public boolean saveAs ( \craft\image\string $targetPath, \craft\image\bool $autoQuality = false )

scaleAndCrop()

Scale and crop image to exactly fit the specified size.

View source

Arguments

Returns

static – Self reference

Signature

public static scaleAndCrop ( \craft\image\int $targetWidth = null, \craft\image\int $targetHeight = null, \craft\image\bool $scaleIfSmaller = true, $cropPosition = 'center-center' )

scaleToFit()

Scale the image to fit within the specified size.

View source

Arguments

Returns

static – Self reference

Signature

public static scaleToFit ( \craft\image\int $targetWidth = null, \craft\image\int $targetHeight = null, \craft\image\bool $scaleIfSmaller = true )

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

Signature

public void setFontProperties ( \craft\image\string $fontFile, \craft\image\int $size, \craft\image\string $color )

setInterlace()

Sets the interlace setting.

View source

Arguments

Returns

static – Self reference

Signature

public static setInterlace ( \craft\image\string $interlace )

setQuality()

Sets the image quality.

View source

Arguments

Returns

static – Self reference

Signature

public static setQuality ( \craft\image\int $quality )

writeText()

Writes text on an image.

View source

Arguments

Throws

Signature

public void writeText ( \craft\image\string $text, \craft\image\int $x, \craft\image\int $y, \craft\image\int $angle = 0 )

Protected Methods

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