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.
Public Properties ​
Property | Description |
---|---|
extension | string |
height | integer |
imagineImage | \Imagine\Image\AbstractImage , null |
interlace | string |
isTransparent | boolean – Whether the image is transparent |
quality | integer |
width | integer |
extension
​
- Type
- string
- Default value
null
- Access
- Read-only
height
​
- Type
- integer
- Default value
null
- Access
- Read-only
imagineImage
​
- Type
\Imagine\Image\AbstractImage
, null- Default value
null
- Access
- Read-only
interlace
​
- Type
- string
- Default value
null
- Access
- Write-only
quality
​
- Type
- integer
- Default value
null
- Access
- Write-only
width
​
- Type
- integer
- Default value
null
- Access
- Read-only
Public Methods ​
Method | Description |
---|---|
__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. |
heartbeat() | Let everyone back home know we're ok. |
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. |
scaleToFitAndFill() | Scales an image to the target size and fills empty pixels with color. |
setFill() | Sets the fill color based on the image's palette. |
setFontProperties() | Sets properties for text drawing on the image. |
setHeartbeatCallback() | Sets the heartbeat callback. |
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.
Arguments ​
$config
(array) – Name-value pairs that will be used to initialize the object properties
crop()
​
Crops the image to the specified coordinates.
Arguments ​
Returns ​
static
– Self reference
disableAnimation()
​
Disable animation if this is an animated image.
Returns ​
self
– Self-reference
flipHorizontally()
​
Flips the image horizontally.
Returns ​
self
– Self reference
flipVertically()
​
Flips the image vertically.
Returns ​
self
– Self reference
getExifMetadata()
​
Returns EXIF metadata for a file by its path.
Arguments ​
$filePath
(string)
Returns ​
getExtension()
​
Returns the file extension.
Returns ​
getHeight()
​
Returns the height of the image.
Returns ​
getImagineImage()
​
Return the Imagine Image instance
Returns ​
\Imagine\Image\AbstractImage
, null
getIsTransparent()
​
Returns whether the image is transparent.
Returns ​
getTextBox()
​
Returns the bounding text box for a text string and an angle
Arguments ​
Returns ​
\Imagine\Image\BoxInterface
Throws ​
- craft\errors\ImageException
if attempting to create text box with no font properties
getWidth()
​
Returns the width of the image.
Returns ​
loadFromSVG()
​
Loads an image from an SVG string.
Arguments ​
$svgContent
(string)
Returns ​
self
– Self reference
Throws ​
- craft\errors\ImageException
if the SVG string cannot be loaded.
loadImage()
​
Loads an image from a file system path.
Arguments ​
$path
(string)
Returns ​
static
– Self reference
Throws ​
- craft\errors\ImageException
if the file cannot be loaded
resize()
​
Resizes the image.
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.
Arguments ​
$degrees
(float)
Returns ​
self
– Self reference
saveAs()
​
Saves the image to the target path.
Arguments ​
Returns ​
Throws ​
- craft\errors\ImageException
if the image cannot be saved.
scaleAndCrop()
​
Scale and crop image to exactly fit the specified size.
Arguments ​
$targetWidth
(integer, null)$targetHeight
(integer, null)$scaleIfSmaller
(boolean)$cropPosition
(string, string[])
Returns ​
static
– Self reference
scaleToFit()
​
Scale the image to fit within the specified size.
Arguments ​
Returns ​
static
– Self reference
scaleToFitAndFill()
​
- Since
- 4.4.0
Scales an image to the target size and fills empty pixels with color.
Arguments ​
$targetWidth
(integer, null)$targetHeight
(integer, null)$fill
(string, null)$position
(string, array)$upscale
(boolean, null)
Returns ​
setFill()
​
- Since
- 4.4.0
Sets the fill color based on the image's palette.
Arguments ​
$fill
(string) – Hex color of the fill.
Returns ​
$this – Self reference
setFontProperties()
​
Sets properties for text drawing on the image.
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.
Arguments ​
$interlace
(string)
Returns ​
self
– Self reference
setQuality()
​
Sets the image quality.
Arguments ​
$quality
(integer)
Returns ​
self
– Self reference
writeText()
​
Writes text on an image.
Arguments ​
Throws ​
- craft\errors\ImageException
If attempting to create text box with no font properties et.
Protected Methods ​
Method | Description |
---|---|
normalizeDimensions() | Normalizes the given dimensions. If width or height is set to 'AUTO', we calculate the missing dimension. |