Craft 3 Class Reference

Class craft\image\Raster

Inheritance
craft\image\Raster » craft\base\Image » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/image/Raster.php

Raster class is used for raster image manipulations.

Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. craft\image\Raster
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
crop() Crops the image to the specified coordinates. craft\image\Raster
flipHorizontally() Flips the image horizontally. craft\image\Raster
flipVertically() Flips the image vertically. craft\image\Raster
getExifMetadata() Returns EXIF metadata for a file by its path. craft\image\Raster
getExtension() Returns the file extension. craft\image\Raster
getHeight() Returns the height of the image. craft\image\Raster
getImagineImage() Return the Imagine Image instance craft\image\Raster
getIsTransparent() Returns whether the image is transparent. craft\image\Raster
getTextBox() Returns the bounding text box for a text string and an angle craft\image\Raster
getWidth() Returns the width of the image. craft\image\Raster
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
loadFromSVG() Loads an image from an SVG string. craft\image\Raster
loadImage() Loads an image from a file system path. craft\image\Raster
resize() Resizes the image. craft\image\Raster
rotate() Rotates the image by the given degrees. craft\image\Raster
saveAs() Saves the image to the target path. craft\image\Raster
scaleAndCrop() Scale and crop image to exactly fit the specified size. craft\image\Raster
scaleToFit() Scale the image to fit within the specified size. craft\image\Raster
setFontProperties() Sets properties for text drawing on the image. craft\image\Raster
setInterlace() Sets the interlace setting. craft\image\Raster
setQuality() Sets the image quality. craft\image\Raster
writeText() Writes text on an image. craft\image\Raster
Protected Methods
Method Description Defined By
normalizeDimensions() Normalizes the given dimensions. If width or height is set to 'AUTO', we calculate the missing dimension. craft\base\Image

Method Details

__construct() public method #

Constructor.

The default implementation does two things:

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

public void __construct ( $config = [] )
$config array Name-value pairs that will be used to initialize the object properties

crop() public method #

Crops the image to the specified coordinates.

public static crop ( \craft\image\int $x1, \craft\image\int $x2, \craft\image\int $y1, \craft\image\int $y2 )
$x1 integer
$x2 integer
$y1 integer
$y2 integer
return static Self reference

flipHorizontally() public method #

Flips the image horizontally.

public static flipHorizontally ( )
return static Self reference

flipVertically() public method #

Flips the image vertically.

public static flipVertically ( )
return static Self reference

getExifMetadata() public method #

Returns EXIF metadata for a file by its path.

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

getExtension() public method #

Returns the file extension.

public string getExtension ( )

getHeight() public method #

Returns the height of the image.

public integer getHeight ( )

getImagineImage() public method #

Return the Imagine Image instance

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

getIsTransparent() public method #

Returns whether the image is transparent.

public boolean getIsTransparent ( )

getTextBox() public method #

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

public \Imagine\Image\BoxInterface getTextBox ( \craft\image\string $text, \craft\image\int $angle 0 )
$text string
$angle integer
throws craft\errors\ImageException if attempting to create text box with no font properties

getWidth() public method #

Returns the width of the image.

public integer getWidth ( )

loadFromSVG() public method #

Loads an image from an SVG string.

public static loadFromSVG ( \craft\image\string $svgContent )
$svgContent string
return static Self reference
throws craft\errors\ImageException if the SVG string cannot be loaded.

loadImage() public method #

Loads an image from a file system path.

public static, craft\image\Svg loadImage ( \craft\image\string $path )
$path string
return static, craft\image\Svg Self reference
throws craft\errors\ImageException if the file cannot be loaded

resize() public method #

Resizes the image.

public static resize ( \craft\image\int $targetWidth null, \craft\image\int $targetHeight null )
$targetWidth integer The target width
$targetHeight integer, null The target height. Defaults to $targetWidth if omitted, creating a square.
return static Self reference

rotate() public method #

Rotates the image by the given degrees.

public static rotate ( \craft\image\float $degrees )
$degrees float
return static Self reference

saveAs() public method #

Saves the image to the target path.

public boolean saveAs ( \craft\image\string $targetPath, \craft\image\bool $autoQuality false )
$targetPath string
$autoQuality boolean
throws craft\errors\ImageException if the image cannot be saved.

scaleAndCrop() public method #

Scale and crop image to exactly fit the specified size.

public static scaleAndCrop ( \craft\image\int $targetWidth null, \craft\image\int $targetHeight null, \craft\image\bool $scaleIfSmaller true, $cropPosition 'center-center' )
$targetWidth integer, null
$targetHeight integer, null
$scaleIfSmaller boolean
$cropPosition mixed
return static Self reference

scaleToFit() public method #

Scale the image to fit within the specified size.

public static scaleToFit ( \craft\image\int $targetWidth null, \craft\image\int $targetHeight null, \craft\image\bool $scaleIfSmaller true )
$targetWidth integer
$targetHeight integer, null
$scaleIfSmaller boolean
return static Self reference

setFontProperties() public method #

Sets properties for text drawing on the image.

public void setFontProperties ( \craft\image\string $fontFile, \craft\image\int $size, \craft\image\string $color )
$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() public method #

Sets the interlace setting.

public static setInterlace ( \craft\image\string $interlace )
$interlace string
return static Self reference

setQuality() public method #

Sets the image quality.

public static setQuality ( \craft\image\int $quality )
$quality integer
return static Self reference

writeText() public method #

Writes text on an image.

public void writeText ( \craft\image\string $text, \craft\image\int $x, \craft\image\int $y, \craft\image\int $angle 0 )
$text string
$x integer
$y integer
$angle integer
throws craft\errors\ImageException If attempting to create text box with no font properties et.