\Grafika\ImagickEditor

Imagick Editor class. Uses the PHP Imagick library.

Summary

Methods
Properties
Constants
apply()
blend()
compare()
crop()
draw()
equal()
fill()
flatten()
flip()
free()
isAvailable()
opacity()
open()
resize()
resizeExact()
resizeExactHeight()
resizeExactWidth()
resizeFill()
resizeFit()
rotate()
save()
text()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
_entropy()
_smartCrop()
_resize()
_getImageTypeFromFileName()
No private properties found
N/A

Methods

apply()

apply(\Grafika\Imagick\Image  $image, \Grafika\FilterInterface  $filter) : \Grafika\Imagick\Editor

Apply a filter to the image. See Filters section for a list of available filters.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

\Grafika\FilterInterface $filter

Instance implementing the FilterInterface.

Returns

\Grafika\Imagick\Editor

blend()

blend(\Grafika\Imagick\Image  $image1, \Grafika\Imagick\Image  $image2, string  $type = 'normal', float  $opacity = 1.0, string  $position = 'top-left', integer  $offsetX, integer  $offsetY) : \Grafika\Imagick\Editor

Blend two images together with the first image as the base and the second image on top. Supports several blend modes.

Parameters

\Grafika\Imagick\Image $image1

The base image.

\Grafika\Imagick\Image $image2

The image placed on top of the base image.

string $type

The blend mode. Can be: normal, multiply, overlay or screen.

float $opacity

The opacity of $image2. Possible values 0.0 to 1.0 where 0.0 is fully transparent and 1.0 is fully opaque. Defaults to 1.0.

string $position

The position of $image2 on $image1. Possible values top-left, top-center, top-right, center-left, center, center-right, bottom-left, bottom-center, bottom-right and smart. Defaults to top-left.

integer $offsetX

Number of pixels to add to the X position of $image2.

integer $offsetY

Number of pixels to add to the Y position of $image2.

Throws

\Exception

When added image is outside of canvas or invalid blend type

Returns

\Grafika\Imagick\Editor

compare()

compare(\Grafika\ImageInterface|string  $image1, \Grafika\ImageInterface|string  $image2) : integer

Compare two images and returns a hamming distance. A value of 0 indicates a likely similar picture. A value between 1 and 10 is potentially a variation. A value greater than 10 is likely a different image.

Parameters

\Grafika\ImageInterface|string $image1

Can be an instance of Image or string containing the file system path to image.

\Grafika\ImageInterface|string $image2

Can be an instance of Image or string containing the file system path to image.

Throws

\Exception

Returns

integer —

Hamming distance. Note: This breaks the chain if you are doing fluent api calls as it does not return an Editor.

crop()

crop(\Grafika\Imagick\Image  $image, integer  $cropWidth, integer  $cropHeight, string  $position = 'center', integer  $offsetX, integer  $offsetY) : \Grafika\Imagick\Editor

Crop the image to the given dimension and position.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

integer $cropWidth

Crop width in pixels.

integer $cropHeight

Crop Height in pixels.

string $position

The crop position. Possible values top-left, top-center, top-right, center-left, center, center-right, bottom-left, bottom-center, bottom-right and smart. Defaults to center.

integer $offsetX

Number of pixels to add to the X position of the crop.

integer $offsetY

Number of pixels to add to the Y position of the crop.

Throws

\Exception

Returns

\Grafika\Imagick\Editor

draw()

draw(\Grafika\Imagick\Image  $image, \Grafika\DrawingObjectInterface  $drawingObject) : $this

Draw a DrawingObject on the image. See Drawing Objects section.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

\Grafika\DrawingObjectInterface $drawingObject

Instance of DrawingObject.

Returns

$this

equal()

equal(string|\Grafika\ImageInterface  $image1, string|\Grafika\ImageInterface  $image2) : boolean

Compare if two images are equal. It will compare if the two images are of the same width and height. If the dimensions differ, it will return false. If the dimensions are equal, it will loop through each pixels. If one of the pixel don't match, it will return false. The pixels are compared using their RGB (Red, Green, Blue) values.

Parameters

string|\Grafika\ImageInterface $image1

Can be an instance of Image or string containing the file system path to image.

string|\Grafika\ImageInterface $image2

Can be an instance of Image or string containing the file system path to image.

Throws

\Exception

Returns

boolean —

True if equals false if not. Note: This breaks the chain if you are doing fluent api calls as it does not return an Editor.

fill()

fill(\Grafika\Imagick\Image  $image, \Grafika\Color  $color, integer  $x, integer  $y) : self

Fill entire image with color.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

\Grafika\Color $color

Color object

integer $x

X-coordinate of start point

integer $y

Y-coordinate of start point

Returns

self

flatten()

flatten(\Grafika\Imagick\Image  $image) : self

Flatten if animated GIF. Do nothing otherwise.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

Returns

self

flip()

flip(\Grafika\Imagick\Image  $image, string  $mode) : \Grafika\Imagick\Editor

Flip or mirrors the image.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

string $mode

The type of flip: 'h' for horizontal flip or 'v' for vertical.

Throws

\Exception

Returns

\Grafika\Imagick\Editor

isAvailable()

isAvailable() : boolean

Checks if the editor is available on the current PHP install.

Returns

boolean —

True if available false if not.

opacity()

opacity(\Grafika\Imagick\Image  $image, float  $opacity) : self

Sets the image to the specified opacity level where 1.0 is fully opaque and 0.0 is fully transparent.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

float $opacity

The opacity level where 1.0 is fully opaque and 0.0 is fully transparent.

Throws

\Exception

Returns

self

open()

open(\Grafika\Imagick\Image  $image, string  $imageFile) : \Grafika\Imagick\Editor

Open an image file and assign Image to first parameter.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

string $imageFile

File system path to image file.

Returns

\Grafika\Imagick\Editor

resize()

resize(\Grafika\Imagick\Image  $image, integer  $newWidth, integer  $newHeight, string  $mode = 'fit') : \Grafika\Imagick\Editor

Wrapper function for the resizeXXX family of functions. Resize image given width, height and mode.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

integer $newWidth

Width in pixels.

integer $newHeight

Height in pixels.

string $mode

Resize mode. Possible values: "exact", "exactHeight", "exactWidth", "fill", "fit".

Throws

\Exception

Returns

\Grafika\Imagick\Editor

resizeExact()

resizeExact(\Grafika\Imagick\Image  $image, integer  $newWidth, integer  $newHeight) : self

Resize image to exact dimensions ignoring aspect ratio. Useful if you want to force exact width and height.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

integer $newWidth

Width in pixels.

integer $newHeight

Height in pixels.

Returns

self

resizeExactHeight()

resizeExactHeight(\Grafika\Imagick\Image  $image, integer  $newHeight) : self

Resize image to exact height. Width is auto calculated. Useful for creating row of images with the same height.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

integer $newHeight

Height in pixels.

Returns

self

resizeExactWidth()

resizeExactWidth(\Grafika\Imagick\Image  $image, integer  $newWidth) : self

Resize image to exact width. Height is auto calculated. Useful for creating column of images with the same width.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

integer $newWidth

Width in pixels.

Returns

self

resizeFill()

resizeFill(\Grafika\Imagick\Image  $image, integer  $newWidth, integer  $newHeight) : self

Resize image to fill all the space in the given dimension. Excess parts are cropped.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

integer $newWidth

Width in pixels.

integer $newHeight

Height in pixels.

Returns

self

resizeFit()

resizeFit(\Grafika\Imagick\Image  $image, integer  $newWidth, integer  $newHeight) : self

Resize image to fit inside the given dimension. No part of the image is lost.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

integer $newWidth

Width in pixels.

integer $newHeight

Height in pixels.

Returns

self

rotate()

rotate(\Grafika\Imagick\Image  $image, integer  $angle, \Grafika\Color|null  $color = null) : \Grafika\EditorInterface

Rotate an image counter-clockwise.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

integer $angle

The angle in degrees.

\Grafika\Color|null $color

The Color object containing the background color.

Returns

\Grafika\EditorInterface

An instance of image editor.

save()

save(\Grafika\Imagick\Image  $image, string  $file, null|string  $type = null, null|string  $quality = null, boolean|false  $interlace = false, integer  $permission = 493) : \Grafika\Imagick\Editor

Save the image to an image format.

Parameters

\Grafika\Imagick\Image $image

Instance of Image. Saving the image to a different format will have NO effect on the Image instance.

string $file

File path where to save the image.

null|string $type

Type of image. Can be null, "GIF", "PNG", or "JPEG".

null|string $quality

Quality of image. Applies to JPEG only. Accepts number 0 - 100 where 0 is lowest and 100 is the highest quality. Or null for default.

boolean|false $interlace

Set to true for progressive JPEG. Applies to JPEG only.

integer $permission

Default permission when creating non-existing target directory.

Throws

\Exception

Returns

\Grafika\Imagick\Editor

text()

text(\Grafika\Imagick\Image  $image, string  $text, integer  $size = 12, integer  $x, integer  $y, \Grafika\Color  $color = null, string  $font = '', integer  $angle) : \Grafika\EditorInterface

Write text to image.

Parameters

\Grafika\Imagick\Image $image

Instance of Image.

string $text

The text to be written.

integer $size

The font size. Defaults to 12.

integer $x

The distance from the left edge of the image to the left of the text. Defaults to 0.

integer $y

The distance from the top edge of the image to the top of the text. Defaults to 12 (equal to font size) so that the text is placed within the image.

\Grafika\Color $color

The Color object. Default text color is black.

string $font

Full path to font file. If blank, will default to Liberation Sans font.

integer $angle

Angle of text from 0 - 359. Defaults to 0.

Throws

\Exception

Returns

\Grafika\EditorInterface

_entropy()

_entropy(array  $hist) : float|integer

Calculate entropy based on histogram.

Parameters

array $hist

Histogram returned by Image->histogram

Returns

float|integer

_smartCrop()

_smartCrop(\Grafika\Imagick\Image  $oldImage,   $cropW,   $cropH) : array

Crop based on entropy.

Parameters

\Grafika\Imagick\Image $oldImage
$cropW
$cropH

Returns

array

_resize()

_resize(\Grafika\Imagick\Image  $image, integer  $newWidth, integer  $newHeight) : self

Resize helper function.

Parameters

\Grafika\Imagick\Image $image
integer $newWidth
integer $newHeight

Throws

\Exception

Returns

self

_getImageTypeFromFileName()

_getImageTypeFromFileName(integer  $imageFile) : \Grafika\ImageType

Get image type base on file extension.

Parameters

integer $imageFile

File path to image.

Returns

\Grafika\ImageType

string Type of image.