Image

Type
Class
Namespace
Craft
Inherits
Craft\Image » Craft\BaseImage
Since
2.5

Class Image

See also http://craftcms.com

View source

Public Methods

MethodDescription
__construct()
crop()Crops the image to the specified coordinates.
disableAnimation()Disable animation if this is an animated image.
getExifMetadata()Return EXIF metadata for a file by it's path
getExtension()
getHeight()
getTextBox()Get the bounding text box for a text string and an angle
getWidth()
isTransparent()Returns true if Imagick is installed and says that the image is transparent.
loadFromSVG()Load an image from an SVG string.
loadImage()Loads an image from a file system path.
resize()Re-sizes the image. If $height is not specified, it will default to $width, creating a square.
rotate()Rotate an image by 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.
setFontProperties()Set properties for text drawing on the image.
setQuality()Set image quality.
writeText()Write text on an image

__construct()

Signature

public Craft\Image __construct ( )

crop()

Crops the image to the specified coordinates.

View source

Arguments

Returns

Craft\Image

Signature

public Craft\Image crop ( $x1, $x2, $y1, $y2 )

disableAnimation()

Disable animation if this is an animated image.

View source

Returns

$this

Signature

public $this disableAnimation ( )

getExifMetadata()

Return EXIF metadata for a file by it's path

View source

Arguments

  • $filePath

Returns

array

Signature

public array getExifMetadata ( $filePath )

getExtension()

Signature

public string getExtension ( )

getHeight()

Signature

public integer getHeight ( )

getTextBox()

Get the bounding text box for a text string and an angle

View source

Arguments

Returns

\Imagine\Image\BoxInterface

Throws

Signature

public \Imagine\Image\BoxInterface getTextBox ( $text, $angle = 0 )

getWidth()

Signature

public integer getWidth ( )

isTransparent()

Returns true if Imagick is installed and says that the image is transparent.

View source

Returns

boolean

Signature

public boolean isTransparent ( )

loadFromSVG()

Load an image from an SVG string.

View source

Arguments

  • $svgContent

Returns

Craft\Image

Signature

public Craft\Image loadFromSVG ( $svgContent )

loadImage()

Loads an image from a file system path.

View source

Arguments

Returns

Craft\Image

Throws

Signature

public Craft\Image loadImage ( $path )

resize()

Re-sizes the image. If $height is not specified, it will default to $width, creating a square.

View source

Arguments

Returns

Craft\Image

Signature

public Craft\Image resize ( $targetWidth, $targetHeight = null )

rotate()

Rotate an image by degrees.

View source

Arguments

Returns

Craft\Image

Signature

public Craft\Image rotate ( $degrees )

saveAs()

Saves the image to the target path.

View source

Arguments

  • $targetPath (string)
  • $autoQuality

Returns

null

Throws

  • \Imagine\Exception\RuntimeException

Signature

public null saveAs ( $targetPath, $autoQuality = false )

scaleAndCrop()

Scale and crop image to exactly fit the specified size.

View source

Arguments

Returns

Craft\Image

Signature

public Craft\Image scaleAndCrop ( $targetWidth, $targetHeight = null, $scaleIfSmaller = true, $cropPositions = 'center-center' )

scaleToFit()

Scale the image to fit within the specified size.

View source

Arguments

Returns

Craft\Image

Signature

public Craft\Image scaleToFit ( $targetWidth, $targetHeight = null, $scaleIfSmaller = true )

setFontProperties()

Set properties for text drawing on the image.

View source

Arguments

  • $fontFile – String path to the font file on server
  • $size – Int font size to use
  • $color – String font color to use in hex format

Returns

null

Signature

public null setFontProperties ( $fontFile, $size, $color )

setQuality()

Set image quality.

View source

Arguments

Returns

Craft\Image

Signature

public Craft\Image setQuality ( $quality )

writeText()

Write text on an image

View source

Arguments

Returns

null

Throws

Signature

public null writeText ( $text, $x, $y, $angle = 0 )

Protected Methods

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