ImageHelper

Type
Class
Namespace
Craft
Inherits
Craft\ImageHelper
Since
1.1

Class ImageHelper

See also http://craftcms.com

View source

Public Methods

MethodDescription
calculateMissingDimension()Calculates a missing target dimension for an image.
canHaveExifData()Returns whether an image can have EXIF information embedded.
getImageSize()Returns the size of an image based on its file path.
getPngImageInfo()Returns any info that’s embedded in a given PNG file.
getWebSafeFormats()Returns a list of web safe image formats.
isImageManipulatable()Returns whether an image extension is considered manipulatable.
parseSvgSize()Parses SVG data and determines its size (normalized to pixels).

calculateMissingDimension()

Calculates a missing target dimension for an image.

View source

Arguments

  • $targetWidth
  • $targetHeight
  • $sourceWidth
  • $sourceHeight

Returns

array – Array of the width and height.

Signature

public static array calculateMissingDimension ( $targetWidth, $targetHeight, $sourceWidth, $sourceHeight )

canHaveExifData()

Returns whether an image can have EXIF information embedded.

View source

Arguments

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

Returns

boolean

Signature

public static boolean canHaveExifData ( $filePath )

getImageSize()

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 getImageSize ( $filePath )

getPngImageInfo()

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 getPngImageInfo ( $file )

getWebSafeFormats()

Returns a list of web safe image formats.

View source

Returns

array

Signature

public static array getWebSafeFormats ( )

isImageManipulatable()

Returns whether an image extension is considered manipulatable.

View source

Arguments

  • $extension

Returns

boolean

Signature

public static boolean isImageManipulatable ( $extension )

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 ( $svg )

Constants

ConstantDescription
EXIF_IFD0_ROTATE_180
EXIF_IFD0_ROTATE_270
EXIF_IFD0_ROTATE_90