Svg

Type
Class
Namespace
craft\image
Inherits
craft\image\Svg » craft\base\Image » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0

Svg class is used for SVG file manipulations.

View source

Public Properties

$extension

Type
string
Access
Read-only

View source

Signature

public string getExtension ( )

$height

Type
integer
Access
Read-only

View source

Signature

public integer getHeight ( )

$isTransparent

Type
boolean
Access
Read-only

View source

Signature

public boolean getIsTransparent ( )

$svgString

Type
string
Access
Read-only

View source

Signature

public string getSvgString ( )

$width

Type
integer
Access
Read-only

View source

Signature

public integer getWidth ( )

Public Methods

MethodDescription
__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.
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.

crop()

Crops the image to the specified coordinates.

View source

Arguments

Returns

static – Self reference

Signature

public static crop ( \craft\image\int $x1, \craft\image\int $x2, \craft\image\int $y1, \craft\image\int $y2 )

getExtension()

Returns the file extension.

View source

Returns

string

Signature

public string getExtension ( )

getHeight()

Returns the height of the image.

View source

Returns

integer

Signature

public integer getHeight ( )

getIsTransparent()

Returns whether the image is transparent.

View source

Returns

boolean

Signature

public boolean getIsTransparent ( )

getSvgString()

Returns the SVG string.

View source

Returns

string

Signature

public string getSvgString ( )

getWidth()

Returns the width of the image.

View source

Returns

integer

Signature

public integer getWidth ( )

loadImage()

Loads an image from a file system path.

View source

Arguments

Returns

static, craft\image\Svg – Self reference

Throws

Signature

public static, craft\image\Svg loadImage ( \craft\image\string $path )

resize()

Resizes the image.

View source

Arguments

  • $targetWidth (integer) – The target width
  • $targetHeight (integer, null) – The target height. Defaults to $targetWidth if omitted, creating a square.

Returns

static – Self reference

Signature

public static resize ( \craft\image\int $targetWidth, \craft\image\int $targetHeight = null )

saveAs()

Saves the image to the target path.

View source

Arguments

Returns

boolean

Throws

Signature

public boolean saveAs ( \craft\image\string $targetPath, \craft\image\bool $autoQuality = false )

scaleAndCrop()

Scale and crop image to exactly fit the specified size.

View source

Arguments

Returns

static – Self reference

Signature

public static scaleAndCrop ( \craft\image\int $targetWidth = null, \craft\image\int $targetHeight = null, \craft\image\bool $scaleIfSmaller = true, $cropPosition = 'center-center' )

scaleToFit()

Scale the image to fit within the specified size.

View source

Arguments

Returns

static – Self reference

Signature

public static scaleToFit ( \craft\image\int $targetWidth, \craft\image\int $targetHeight = null, \craft\image\bool $scaleIfSmaller = true )

Protected Methods

MethodDescription
normalizeDimensions()Normalizes the given dimensions. If width or height is set to 'AUTO', we calculate the missing dimension.

Constants

ConstantDescription
SVG_ASPECT_RE
SVG_CLEANUP_HEIGHT_RE
SVG_CLEANUP_WIDTH_RE
SVG_HEIGHT_RE
SVG_TAG_RE
SVG_VIEWBOX_RE
SVG_WIDTH_RE