Svg
- Type
- Class
- Namespace
- craft\image
- Inherits
- craft\image\Svg » craft\base\Image » yii\base\BaseObject (opens new window)
- Implements
- yii\base\Configurable (opens new window)
- Since
- 3.0.0
Svg class is used for SVG file manipulations.
View source (opens new window)
# Public Properties
Property | Description |
---|---|
extension | string (opens new window) |
height | integer (opens new window) |
isTransparent | boolean (opens new window) – Whether the image is transparent |
svgString | string (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)
# svgString
- Type
- string (opens new window)
- Default value
null
- Access
- Read-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() (opens new window) | 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. |
getExtension() | Returns the file extension. |
getHeight() | Returns the height of the image. |
getIsTransparent() | Returns whether the image is transparent. |
getSvgString() | Returns the SVG string. |
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. |
loadImage() | Loads an image from a file system path. |
resize() | Resizes the image. |
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. |
setHeartbeatCallback() | Sets the heartbeat callback. |
# 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
# getExtension()
Returns the file extension.
View source (opens new window)
Returns
# getHeight()
Returns the height of the image.
View source (opens new window)
Returns
# getIsTransparent()
Returns whether the image is transparent.
View source (opens new window)
Returns
# getSvgString()
Returns the SVG string.
View source (opens new window)
Returns
# getWidth()
Returns the width of the image.
View source (opens new window)
Returns
# 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
# 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
# Protected Methods
Method | Description |
---|---|
normalizeDimensions() | Normalizes the given dimensions. If width or height is set to 'AUTO', we calculate the missing dimension. |
# Constants
Constant | Description |
---|---|
SVG_ASPECT_RE | |
SVG_CLEANUP_HEIGHT_RE | |
SVG_CLEANUP_WIDTH_RE | |
SVG_HEIGHT_RE | |
SVG_TAG_RE | |
SVG_VIEWBOX_RE | |
SVG_WIDTH_RE |