Image

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

Class Image

See also http://craftcms.com

View source (opens new window)

# Public Methods

Method Description
__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()

Signature

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

# disableAnimation()

Disable animation if this is an animated image.

View source (opens new window)

Returns

$this

Signature

public $this disableAnimation ( )

# getExifMetadata()

Return EXIF metadata for a file by it's path

View source (opens new window)

Arguments

  • $filePath

Returns

array (opens new window)

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 (opens new window)

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 (opens new window)

Returns

boolean (opens new window)

Signature

public boolean isTransparent ( )

# loadFromSVG()

Load an image from an SVG string.

View source (opens new window)

Arguments

  • $svgContent

Returns

Craft\Image

Signature

public Craft\Image loadFromSVG ( $svgContent )

# loadImage()

Loads an image from a file system path.

View source (opens new window)

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 (opens new window)

Arguments

Returns

Craft\Image

Signature

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

# rotate()

Rotate an image by degrees.

View source (opens new window)

Arguments

Returns

Craft\Image

Signature

public Craft\Image rotate ( $degrees )

# saveAs()

Saves the image to the target path.

View source (opens new window)

Arguments

Returns

null (opens new window)

Throws

  • \Imagine\Exception\RuntimeException

Signature

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

# scaleAndCrop()

Scale and crop image to exactly fit the specified size.

View source (opens new window)

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 (opens new window)

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 (opens new window)

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 (opens new window)

Signature

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

# setQuality()

Set image quality.

View source (opens new window)

Arguments

Returns

Craft\Image

Signature

public Craft\Image setQuality ( $quality )

# writeText()

Write text on an image

View source (opens new window)

Arguments

Returns

null (opens new window)

Throws

Signature

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

# Protected Methods

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