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()
Crops the image to the specified coordinates.
View source (opens new window)
Arguments
$x1
(integer (opens new window))$x2
(integer (opens new window))$y1
(integer (opens new window))$y2
(integer (opens new window))
Returns
Signature
public Craft\Image crop ( $x1, $x2, $y1, $y2 )
# disableAnimation()
Signature
public $this disableAnimation ( )
# getExifMetadata()
Return EXIF metadata for a file by it's path
View source (opens new window)
Arguments
$filePath
Returns
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
$text
$angle
(integer (opens new window))
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
Signature
public boolean isTransparent ( )
# loadFromSVG()
Signature
public Craft\Image loadFromSVG ( $svgContent )
# loadImage()
Loads an image from a file system path.
View source (opens new window)
Arguments
$path
(string (opens new window))
Returns
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
$targetWidth
(integer (opens new window))$targetHeight
(integer (opens new window), null (opens new window))
Returns
Signature
public Craft\Image resize ( $targetWidth, $targetHeight = null )
# rotate()
Rotate an image by degrees.
View source (opens new window)
Arguments
$degrees
(integer (opens new window))
Returns
Signature
public Craft\Image rotate ( $degrees )
# saveAs()
Saves the image to the target path.
View source (opens new window)
Arguments
$targetPath
(string (opens new window))$autoQuality
Returns
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
$targetWidth
(integer (opens new window))$targetHeight
(integer (opens new window), null (opens new window))$scaleIfSmaller
(boolean (opens new window))$cropPositions
(string (opens new window))
Returns
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
$targetWidth
(integer (opens new window))$targetHeight
(integer (opens new window), null (opens new window))$scaleIfSmaller
(boolean (opens new window))
Returns
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
Signature
public null setFontProperties ( $fontFile, $size, $color )
# setQuality()
Set image quality.
View source (opens new window)
Arguments
$quality
(integer (opens new window))
Returns
Signature
public Craft\Image setQuality ( $quality )
# writeText()
Write text on an image
View source (opens new window)
Arguments
$text
$x
$y
$angle
(integer (opens new window))
Returns
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. |