Image

Type
Class
Namespace
craft\helpers
Inherits
craft\helpers\Image
Since
3.0

Class Image

View source

Public Methods

MethodDescription
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.
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.
parseSvgSize()Parses SVG data and determines its size (normalized to pixels).
pngImageInfo()Returns any info that’s embedded in a given PNG file.
webSafeFormats()Returns a list of web safe image formats.

calculateMissingDimension()

Calculates a missing target dimension for an image.

View source

Arguments

Returns

integer[] – Array of the width and height.

Signature

public static integer[] calculateMissingDimension ( $targetWidth, $targetHeight, $sourceWidth, $sourceHeight )

canHaveExifData()

Returns whether an image can have EXIF information embedded.

View source

Arguments

  • $filePath (string) – The file path to check.

Returns

boolean

Signature

public static boolean canHaveExifData ( \craft\helpers\string $filePath )

canManipulateAsImage()

Returns whether an image extension is considered manipulatable.

View source

Arguments

Returns

boolean

Signature

public static boolean canManipulateAsImage ( \craft\helpers\string $extension )

cleanImageByPath()

Clean an image provided by path from all malicious code and the like.

View source

Arguments

Signature

public static void cleanImageByPath ( \craft\helpers\string $imagePath )

imageSize()

Returns the size of an image based on its file path.

View source

Arguments

  • $filePath (string) – The path to the image

Returns

array – [width, height]

Signature

public static array imageSize ( \craft\helpers\string $filePath )

imageSizeByStream()

Determines image dimensions by a stream pointing to the start of the image.

View source

Arguments

Returns

array, false

Throws

Signature

public static array, false imageSizeByStream ( $stream )

parseSvgSize()

Parses SVG data and determines its size (normalized to pixels).

View source

Arguments

  • $svg (string) – The SVG data

Returns

array – [width, height]

Signature

public static array parseSvgSize ( \craft\helpers\string $svg )

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

Arguments

  • $file (string) – The path to the PNG file.

Returns

array, boolean – Info embedded in the PNG file, or false if it wasn’t found.

Signature

public static array, boolean pngImageInfo ( \craft\helpers\string $file )

webSafeFormats()

Returns a list of web safe image formats.

View source

Returns

string[]

Signature

public static string[] webSafeFormats ( )

Constants

ConstantDescription
EXIF_IFD0_ROTATE_180
EXIF_IFD0_ROTATE_270
EXIF_IFD0_ROTATE_90