Craft 3 Class Reference

Class craft\helpers\Image

Inheritance
craft\helpers\Image
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/helpers/Image.php

Class Image

Public Methods
Method Description Defined By
calculateMissingDimension() Calculates a missing target dimension for an image. craft\helpers\Image
canHaveExifData() Returns whether an image can have EXIF information embedded. craft\helpers\Image
canManipulateAsImage() Returns whether an image extension is considered manipulatable. craft\helpers\Image
cleanImageByPath() Clean an image provided by path from all malicious code and the like. craft\helpers\Image
imageSize() Returns the size of an image based on its file path. craft\helpers\Image
imageSizeByStream() Determines image dimensions by a stream pointing to the start of the image. craft\helpers\Image
parseSvgSize() Parses SVG data and determines its size (normalized to pixels). craft\helpers\Image
pngImageInfo() Returns any info that’s embedded in a given PNG file. craft\helpers\Image
webSafeFormats() Returns a list of web safe image formats. craft\helpers\Image
Constants
Constant Value Description Defined By
EXIF_IFD0_ROTATE_180 3 craft\helpers\Image
EXIF_IFD0_ROTATE_270 8 craft\helpers\Image
EXIF_IFD0_ROTATE_90 6 craft\helpers\Image

Method Details

calculateMissingDimension() public static method #

Calculates a missing target dimension for an image.

public static integer[] calculateMissingDimension ( $targetWidth, $targetHeight, $sourceWidth, $sourceHeight )
$targetWidth integer, float, null
$targetHeight integer, float, null
$sourceWidth integer, float
$sourceHeight integer, float
return integer[] Array of the width and height.

canHaveExifData() public static method #

Returns whether an image can have EXIF information embedded.

public static boolean canHaveExifData ( \craft\helpers\string $filePath )
$filePath string The file path to check.

canManipulateAsImage() public static method #

Returns whether an image extension is considered manipulatable.

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

cleanImageByPath() public static method #

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

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

imageSize() public static method #

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

public static array imageSize ( \craft\helpers\string $filePath )
$filePath string The path to the image
return array [width, height]

imageSizeByStream() public static method #

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

public static array, false imageSizeByStream ( $stream )
$stream resource
throws TypeError

parseSvgSize() public static method #

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

public static array parseSvgSize ( \craft\helpers\string $svg )
$svg string The SVG data
return array [width, height]

pngImageInfo() public static method #

Returns any info that’s embedded in a given PNG file.

Adapted from https://github.com/ktomk/Miscellaneous/tree/master/get_png_imageinfo.

public static array, boolean pngImageInfo ( \craft\helpers\string $file )
$file string The path to the PNG file.
return array, boolean Info embedded in the PNG file, or false if it wasn’t found.

webSafeFormats() public static method #

Returns a list of web safe image formats.

public static string[] webSafeFormats ( )