Raster
- Type
- Class
- Namespace
- craft\image
- Inherits
- craft\image\Raster » craft\base\Image » yii\base\BaseObject (opens new window)
- Implements
- yii\base\Configurable (opens new window)
- Since
- 3.0.0
Raster class is used for raster image manipulations.
View source (opens new window)
# Public Properties
Property | Description |
---|---|
extension | string (opens new window) |
height | integer (opens new window) |
imagineImage | \Imagine\Image\AbstractImage , null (opens new window) |
interlace | string (opens new window) |
isTransparent | boolean (opens new window) – Whether the image is transparent |
quality | integer (opens new window) |
width | integer (opens new window) |
# extension
- Type
- string (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# height
- Type
- integer (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# imagineImage
- Type
\Imagine\Image\AbstractImage
, null (opens new window)- Default value
null
- Access
- Read-only
View source (opens new window)
# interlace
- Type
- string (opens new window)
- Default value
null
- Access
- Write-only
View source (opens new window)
# quality
- Type
- integer (opens new window)
- Default value
null
- Access
- Write-only
View source (opens new window)
# width
- Type
- integer (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__construct() | Constructor. |
__get() (opens new window) | Returns the value of an object property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__set() (opens new window) | Sets value of an object property. |
__unset() (opens new window) | Sets an object property to null. |
canGetProperty() (opens new window) | Returns a value indicating whether a property can be read. |
canSetProperty() (opens new window) | Returns a value indicating whether a property can be set. |
className() (opens new window) | 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() (opens new window) | Returns a value indicating whether a method is defined. |
hasProperty() (opens new window) | Returns a value indicating whether a property is defined. |
heartbeat() | Let everyone back home know we're ok. |
init() (opens new window) | 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() (opens new window).
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 (opens new window)
Arguments
$config
(array (opens new window)) – Name-value pairs that will be used to initialize the object properties
# crop()
Crops the image to the specified coordinates.
View source (opens new window)
Arguments
$x1
(integer (opens new window))$x2
(integer (opens new window))$y1
(integer (opens new window))$y2
(integer (opens new window))
Returns
static
– Self reference
# disableAnimation()
Disable animation if this is an animated image.
View source (opens new window)
Returns
self
– Self-reference
# flipHorizontally()
Flips the image horizontally.
View source (opens new window)
Returns
self
– Self reference
# flipVertically()
Flips the image vertically.
View source (opens new window)
Returns
self
– Self reference
# getExifMetadata()
Returns EXIF metadata for a file by its path.
View source (opens new window)
Arguments
$filePath
(string (opens new window))
Returns
# getExtension()
Returns the file extension.
View source (opens new window)
Returns
# getHeight()
Returns the height of the image.
View source (opens new window)
Returns
# getImagineImage()
Return the Imagine Image instance
View source (opens new window)
Returns
\Imagine\Image\AbstractImage
, null (opens new window)
# getIsTransparent()
Returns whether the image is transparent.
View source (opens new window)
Returns
# getTextBox()
Returns the bounding text box for a text string and an angle
View source (opens new window)
Arguments
$text
(string (opens new window))$angle
(integer (opens new window))
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.
View source (opens new window)
Returns
# loadFromSVG()
Loads an image from an SVG string.
View source (opens new window)
Arguments
$svgContent
(string (opens new window))
Returns
self
– Self reference
Throws
- craft\errors\ImageException
if the SVG string cannot be loaded.
# loadImage()
Loads an image from a file system path.
View source (opens new window)
Arguments
$path
(string (opens new window))
Returns
static
– Self reference
Throws
- craft\errors\ImageException
if the file cannot be loaded
# resize()
Resizes the image.
View source (opens new window)
Arguments
$targetWidth
(integer (opens new window), null (opens new window)) – The target width$targetHeight
(integer (opens new window), null (opens new window)) – 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 (opens new window)
Arguments
$degrees
(float (opens new window))
Returns
self
– Self reference
# saveAs()
Saves the image to the target path.
View source (opens new window)
Arguments
$targetPath
(string (opens new window))$autoQuality
(boolean (opens new window))
Returns
Throws
- craft\errors\ImageException
if the image cannot be saved.
# scaleAndCrop()
Scale and crop image to exactly fit the specified size.
View source (opens new window)
Arguments
$targetWidth
(integer (opens new window), null (opens new window))$targetHeight
(integer (opens new window), null (opens new window))$scaleIfSmaller
(boolean (opens new window))$cropPosition
(string (opens new window), string (opens new window)[])
Returns
static
– Self reference
# scaleToFit()
Scale the image to fit within the specified size.
View source (opens new window)
Arguments
$targetWidth
(integer (opens new window), null (opens new window))$targetHeight
(integer (opens new window), null (opens new window))$scaleIfSmaller
(boolean (opens new window))
Returns
static
– Self reference
# scaleToFitAndFill()
- Since
- 4.4.0
Scales an image to the target size and fills empty pixels with color.
View source (opens new window)
Arguments
$targetWidth
(integer (opens new window), null (opens new window))$targetHeight
(integer (opens new window), null (opens new window))$fill
(string (opens new window), null (opens new window))$position
(string (opens new window), array (opens new window))$upscale
(boolean (opens new window), null (opens new window))
Returns
# setFill()
- Since
- 4.4.0
Sets the fill color based on the image's palette.
View source (opens new window)
Arguments
$fill
(string (opens new window)) – Hex color of the fill.
Returns
$this – Self reference
# setFontProperties()
Sets properties for text drawing on the image.
View source (opens new window)
Arguments
$fontFile
(string (opens new window)) – Path to the font file on server$size
(integer (opens new window)) – Font size to use$color
(string (opens new window)) – Font color to use in hex format
# setInterlace()
Sets the interlace setting.
View source (opens new window)
Arguments
$interlace
(string (opens new window))
Returns
self
– Self reference
# setQuality()
Sets the image quality.
View source (opens new window)
Arguments
$quality
(integer (opens new window))
Returns
self
– Self reference
# writeText()
Writes text on an image.
View source (opens new window)
Arguments
$text
(string (opens new window))$x
(integer (opens new window))$y
(integer (opens new window))$angle
(integer (opens new window))
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. |
← Translation Svg →