Image
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\Image
- Since
- 3.0.0
Class Image
View source (opens new window)
# Public Methods
Method | Description |
---|---|
calculateMissingDimension() | Calculates a missing target dimension for an image. |
canHaveExifData() | Returns whether an image can have EXIF information embedded. |
canManipulateAsImage() | Returns whether an image extension is considered manipulatable. |
cleanExifDataFromImagickImage() | Clean EXIF data from an image loaded inside an Imagick instance, taking care not to wipe the ICC profile. |
cleanImageByPath() | Clean an image provided by path from all malicious code and the like. |
imageSize() | Returns the size of an image based on its file path. |
imageSizeByStream() | Determines image dimensions by a stream pointing to the start of the image. |
isWebSafe() | Returns whether an extension is web-safe. |
parseSvgSize() | Parses SVG data and determines its size (normalized to pixels). |
pngImageInfo() | Returns any info that’s embedded in a given PNG file. |
targetDimensions() | Returns the target image width and height for an image, based on its transform type and constraints, and whether the source image should be upscaled. |
webSafeFormats() | Returns a list of web-safe image formats. |
# calculateMissingDimension()
Calculates a missing target dimension for an image.
View source (opens new window)
Arguments
$targetWidth
(float (opens new window), integer (opens new window), null (opens new window))$targetHeight
(float (opens new window), integer (opens new window), null (opens new window))$sourceWidth
(float (opens new window), integer (opens new window))$sourceHeight
(float (opens new window), integer (opens new window))
Returns
integer (opens new window)[] – Array of the width and height.
# canHaveExifData()
Returns whether an image can have EXIF information embedded.
View source (opens new window)
Arguments
$filePath
(string (opens new window)) – The file path to check.
Returns
# canManipulateAsImage()
Returns whether an image extension is considered manipulatable.
View source (opens new window)
Arguments
$extension
(string (opens new window))
Returns
# cleanExifDataFromImagickImage()
Clean EXIF data from an image loaded inside an Imagick instance, taking care not to wipe the ICC profile.
View source (opens new window)
Arguments
$imagick
(\Imagick
)
# cleanImageByPath()
Clean an image provided by path from all malicious code and the like.
View source (opens new window)
Arguments
$imagePath
(string (opens new window))
# imageSize()
Returns the size of an image based on its file path.
View source (opens new window)
Arguments
$filePath
(string (opens new window)) – The path to the image
Returns
array (opens new window) – [width, height]
# imageSizeByStream()
Determines image dimensions by a stream pointing to the start of the image.
View source (opens new window)
Arguments
$stream
(resource (opens new window))
Returns
array (opens new window), false (opens new window)
Throws
# isWebSafe()
- Since
- 4.3.6
Returns whether an extension is web-safe.
View source (opens new window)
Arguments
$extension
(string (opens new window))
Returns
# parseSvgSize()
Parses SVG data and determines its size (normalized to pixels).
View source (opens new window)
Arguments
$svg
(string (opens new window)) – The SVG data
Returns
array (opens new window) – [width, height]
# pngImageInfo()
Returns any info that’s embedded in a given PNG file.
Adapted from https://github.com/ktomk/Miscellaneous/tree/master/get_png_imageinfo.
View source (opens new window)
Arguments
$file
(string (opens new window)) – The path to the PNG file.
Returns
array (opens new window), false (opens new window) – Info embedded in the PNG file, or false
if it wasn’t found.
# targetDimensions()
- Since
- 3.7.55
Returns the target image width and height for an image, based on its transform type and constraints, and whether the source image should be upscaled.
View source (opens new window)
Arguments
$sourceWidth
(integer (opens new window))$sourceHeight
(integer (opens new window))$transformWidth
(integer (opens new window), null (opens new window))$transformHeight
(integer (opens new window), null (opens new window))$mode
(string (opens new window)) – The transform mode (crop
,fit
,letterbox
orstretch
)$upscale
(boolean (opens new window), null (opens new window)) – Whether to upscale the image to fill the transform dimensions. Defaults to theupscaleImages
config setting.
Returns
# webSafeFormats()
Returns a list of web-safe image formats.
View source (opens new window)
Returns
# Constants
Constant | Description |
---|---|
EXIF_IFD0_ROTATE_180 | |
EXIF_IFD0_ROTATE_270 | |
EXIF_IFD0_ROTATE_90 |