\duncan3dc\HelpersImage

Summary

Methods
Properties
Constants
getExtension()
getFormatExtension()
getDate()
resize()
img()
create()
save()
rotate()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

getExtension()

getExtension(string $path, string|array $extensions) : string|null

Get the extension of image file from disk.

Only supports png/jpg/gif. Optionally pass an acceptable extension (or array of extensions).

Parameters

string $path

The fully qualified path to the file

string|array $extensions

Acceptable extensions

Returns

string|null

getFormatExtension()

getFormatExtension(integer|string $format, string|array $extensions) : string|null

Get the extension of a type identifier (either a imagetype constant or a mimetype).

Only supports png/jpg/gif. Optionally pass an acceptable extension (or array of extensions).

Parameters

integer|string $format

Either an imagetype constant or a mimetype string

string|array $extensions

Acceptable extensions

Returns

string|null

getDate()

getDate(string $path) : integer|null

Get the date/time an image was taken (using exif data).

Parameters

string $path

The path to the image file, if it starts with a forward slash then an absolute path is assumed, otherwise it is relative to the document root

Returns

integer|null —

Unix timestamp

resize()

resize(array $options) : null

Resize an image, maintaining the same aspect ratio.

If the image is already an appropriate size then it is just copied.

$options:

  • string "fromPath" The path of the current image file
  • string "toPath" The path to save the resized image to
  • int "width" The maximum width that the image can be
  • int "height" The maximum height that the image can be

Parameters

array $options

An array of options (see above)

Returns

null

img()

img(array $options) : string

Automatically resize and create images on the fly.

If the image already exists then it's path is just passed back.

$options:

  • string "path" The path that the images reside in (default: "images/img")
  • string "basename" The filename, without extension, of the image, the extension will be automatically established and appended
  • string "filename" The filename, including extension, of the image. Either this or "basename" must be set
  • int "width" The maximum width that the image can be, if the image is wider it will be resized (maintaining the same aspect ratio)
  • int "height" The maximum height that the image can be, if the image is taller it will be resized (maintaining the same aspect ratio)

Parameters

array $options

An array of options (see above)

Returns

string

create()

create(string $path, integer $format) : resource

Create an image resource from an image on disk.

Parameters

string $path

The path to load the image from

integer $format

Image type constant (http://php.net/manual/en/image.constants.php)

Returns

resource

save()

save(resource $image, string $path, integer $format) : void

Save an image resource to the disk.

Parameters

resource $image

The image resource to save

string $path

The path to save the image too

integer $format

Image type constant (http://php.net/manual/en/image.constants.php)

rotate()

rotate(string $path, integer $rotate) : void

Rotate an image and save it.

If no angle to rotate is passed then we attempt to read it from exif data.

Parameters

string $path

The path of the image to work with, and overwrite

integer $rotate

A specific rotation angle to apply (clockwise)