Svg ​
- Type
- Class
- Namespace
- craft\image
- Inherits
- craft\image\Svg » craft\base\Image » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 3.0.0
Svg class is used for SVG file manipulations.
Public Properties ​
| Property | Description |
|---|---|
| extension | string |
| height | integer |
| isTransparent | boolean – Whether the image is transparent |
| svgString | string |
| width | integer |
extension ​
- Type
- string
- Default value
null- Access
- Read-only
height ​
- Type
- integer
- Default value
null- Access
- Read-only
svgString ​
- Type
- string
- Default value
null- Access
- Read-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. |
| 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() | 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. |
| 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.
Arguments ​
Returns ​
static – Self reference
getExtension() ​
Returns the file extension.
Returns ​
getHeight() ​
Returns the height of the image.
Returns ​
getIsTransparent() ​
Returns whether the image is transparent.
Returns ​
getSvgString() ​
Returns the SVG string.
Returns ​
getWidth() ​
Returns the width of the image.
Returns ​
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
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
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 |