Craft 3 Class Reference

Abstract Class craft\base\Image

Inheritance
craft\base\Image ยป yii\base\BaseObject
Implements
yii\base\Configurable
Subclasses
craft\image\Raster, craft\image\Svg
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/base/Image.php

Base Image class.

Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
crop() Crops the image to the specified coordinates. craft\base\Image
getExtension() Returns the file extension. craft\base\Image
getHeight() Returns the height of the image. craft\base\Image
getIsTransparent() Returns whether the image is transparent. craft\base\Image
getWidth() Returns the width of the image. craft\base\Image
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
loadImage() Loads an image from a file system path. craft\base\Image
resize() Resizes the image. craft\base\Image
saveAs() Saves the image to the target path. craft\base\Image
scaleAndCrop() Scale and crop image to exactly fit the specified size. craft\base\Image
scaleToFit() Scale the image to fit within the specified size. craft\base\Image
Protected Methods
Method Description Defined By
normalizeDimensions() Normalizes the given dimensions. If width or height is set to 'AUTO', we calculate the missing dimension. craft\base\Image

Method Details

crop() public abstract method #

Crops the image to the specified coordinates.

public abstract static crop ( \craft\base\int $x1, \craft\base\int $x2, \craft\base\int $y1, \craft\base\int $y2 )
$x1 integer
$x2 integer
$y1 integer
$y2 integer
return static Self reference

getExtension() public abstract method #

Returns the file extension.

public abstract string getExtension ( )

getHeight() public abstract method #

Returns the height of the image.

public abstract integer getHeight ( )

getIsTransparent() public abstract method #

Returns whether the image is transparent.

public abstract boolean getIsTransparent ( )

getWidth() public abstract method #

Returns the width of the image.

public abstract integer getWidth ( )

loadImage() public abstract method #

Loads an image from a file system path.

public abstract static, craft\image\Svg loadImage ( \craft\base\string $path )
$path string
return static, craft\image\Svg Self reference
throws craft\errors\ImageException if the file cannot be loaded

normalizeDimensions() protected method #

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

protected void normalizeDimensions ( &$width, &$height )
$width integer, string, null
$height integer, string, null

resize() public abstract method #

Resizes the image.

public abstract static resize ( \craft\base\int $targetWidth, \craft\base\int $targetHeight null )
$targetWidth integer The target width
$targetHeight integer, null The target height. Defaults to $targetWidth if omitted, creating a square.
return static Self reference

saveAs() public abstract method #

Saves the image to the target path.

public abstract boolean saveAs ( \craft\base\string $targetPath, \craft\base\bool $autoQuality false )
$targetPath string
$autoQuality boolean
throws craft\errors\ImageException if the image cannot be saved.

scaleAndCrop() public abstract method #

Scale and crop image to exactly fit the specified size.

public abstract static scaleAndCrop ( \craft\base\int $targetWidth null, \craft\base\int $targetHeight null, \craft\base\bool $scaleIfSmaller true, $cropPosition 'center-center' )
$targetWidth integer, null
$targetHeight integer, null
$scaleIfSmaller boolean
$cropPosition mixed
return static Self reference

scaleToFit() public abstract method #

Scale the image to fit within the specified size.

public abstract static scaleToFit ( \craft\base\int $targetWidth, \craft\base\int $targetHeight null, \craft\base\bool $scaleIfSmaller true )
$targetWidth integer
$targetHeight integer, null
$scaleIfSmaller boolean
return static Self reference