class Editor implements EditorInterface

Imagick Editor class. Uses the PHP Imagick library.

Methods

apply(ImageInterface $image, FilterInterface $filter)

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

blend(ImageInterface $image1, ImageInterface $image2, string $type = 'normal', float $opacity = 1.0, string $position = 'top-left', int $offsetX, int $offsetY)

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

int
compare(string|ImageInterface $image1, string|ImageInterface $image2)

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.

crop(ImageInterface $image, int $cropWidth, int $cropHeight, string $position = 'center', int $offsetX, int $offsetY)

Crop the image to the given dimension and position.

draw(ImageInterface $image, DrawingObjectInterface $drawingObject)

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

bool
equal(string|ImageInterface $image1, string|ImageInterface $image2)

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.

fill(ImageInterface $image, Color $color, int $x, int $y)

Fill entire image with color.

flatten(ImageInterface $image)

Flatten if animated GIF. Do nothing otherwise.

flip(ImageInterface $image, string $mode)

Flip or mirrors the image.

free(ImageInterface $image)

Free the image clearing resources associated with it.

bool
isAvailable()

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

opacity(ImageInterface $image, float $opacity)

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

open(ImageInterface $image, string $imageFile)

Open an image file and assign Image to first parameter.

resize(ImageInterface $image, int $newWidth, int $newHeight, string $mode = 'fit')

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

resizeExact(ImageInterface $image, int $newWidth, int $newHeight)

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

resizeExactHeight(ImageInterface $image, int $newHeight)

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

resizeExactWidth(ImageInterface $image, int $newWidth)

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

resizeFill(ImageInterface $image, int $newWidth, int $newHeight)

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

resizeFit(ImageInterface $image, int $newWidth, int $newHeight)

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

rotate(ImageInterface $image, int $angle, Color|null $color = null)

Rotate an image counter-clockwise.

save(ImageInterface $image, string $file, null|string $type = null, null|string $quality = null, bool $interlace = false, int $permission = 493)

Save the image to an image format.

text(ImageInterface $image, string $text, int $size = 12, int $x, int $y, Color $color = null, string $font = '', int $angle)

Write text to image.

Details

at line line 30
EditorInterface apply(ImageInterface $image, FilterInterface $filter)

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

Parameters

ImageInterface $image Instance of Image.
FilterInterface $filter Instance implementing the FilterInterface.

Return Value

EditorInterface An instance of Editor.

at line line 56
EditorInterface blend(ImageInterface $image1, ImageInterface $image2, string $type = 'normal', float $opacity = 1.0, string $position = 'top-left', int $offsetX, int $offsetY)

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

Parameters

ImageInterface $image1 The base image.
ImageInterface $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.
int $offsetX Number of pixels to add to the X position of $image2.
int $offsetY Number of pixels to add to the Y position of $image2.

Return Value

EditorInterface An instance of Editor.

Exceptions

Exception When added image is outside of canvas or invalid blend type

at line line 118
int compare(string|ImageInterface $image1, string|ImageInterface $image2)

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

string|ImageInterface $image1 Can be an instance of Image or string containing the file system path to image.
string|ImageInterface $image2 Can be an instance of Image or string containing the file system path to image.

Return Value

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

Exceptions

Exception

at line line 161
EditorInterface crop(ImageInterface $image, int $cropWidth, int $cropHeight, string $position = 'center', int $offsetX, int $offsetY)

Crop the image to the given dimension and position.

Parameters

ImageInterface $image Instance of Image.
int $cropWidth Crop width in pixels.
int $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.
int $offsetX Number of pixels to add to the X position of the crop.
int $offsetY Number of pixels to add to the Y position of the crop.

Return Value

EditorInterface An instance of Editor.

Exceptions

Exception

at line line 195
EditorInterface draw(ImageInterface $image, DrawingObjectInterface $drawingObject)

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

Parameters

ImageInterface $image Instance of Image.
DrawingObjectInterface $drawingObject Instance of DrawingObject.

Return Value

EditorInterface An instance of Editor.

at line line 216
bool equal(string|ImageInterface $image1, string|ImageInterface $image2)

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|ImageInterface $image1 Can be an instance of Image or string containing the file system path to image.
string|ImageInterface $image2 Can be an instance of Image or string containing the file system path to image.

Return Value

bool 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.

Exceptions

Exception

at line line 275
EditorInterface fill(ImageInterface $image, Color $color, int $x, int $y)

Fill entire image with color.

Parameters

ImageInterface $image Instance of Image.
Color $color An instance of Grafika\Color class.
int $x X-coordinate of start point.
int $y Y-coordinate of start point.

Return Value

EditorInterface An instance of Editor.

at line line 295
EditorInterface flatten(ImageInterface $image)

Flatten if animated GIF. Do nothing otherwise.

Parameters

ImageInterface $image Instance of Image.

Return Value

EditorInterface An instance of Editor.

at line line 320
EditorInterface flip(ImageInterface $image, string $mode)

Flip or mirrors the image.

Parameters

ImageInterface $image Instance of Image.
string $mode The type of flip: 'h' for horizontal flip or 'v' for vertical.

Return Value

EditorInterface An instance of Editor.

Exceptions

Exception

at line line 338
EditorInterface free(ImageInterface $image)

Free the image clearing resources associated with it.

Parameters

ImageInterface $image Instance of Image.

Return Value

EditorInterface An instance of Editor.

at line line 349
bool isAvailable()

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

Return Value

bool True if available false if not.

at line line 373
EditorInterface opacity(ImageInterface $image, float $opacity)

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

Parameters

ImageInterface $image Instance of Image.
float $opacity The opacity level where 1.0 is fully opaque and 0.0 is fully transparent.

Return Value

EditorInterface An instance of Editor.

Exceptions

Exception

at line line 397
EditorInterface open(ImageInterface $image, string $imageFile)

Open an image file and assign Image to first parameter.

Parameters

ImageInterface $image Instance of Image.
string $imageFile File system path to image file.

Return Value

EditorInterface An instance of Editor.

at line line 413
EditorInterface resize(ImageInterface $image, int $newWidth, int $newHeight, string $mode = 'fit')

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

Parameters

ImageInterface $image Instance of Image.
int $newWidth Width in pixels.
int $newHeight Height in pixels.
string $mode Resize mode. Possible values: "exact", "exactHeight", "exactWidth", "fill", "fit".

Return Value

EditorInterface An instance of Editor.

Exceptions

Exception

at line line 453
EditorInterface resizeExact(ImageInterface $image, int $newWidth, int $newHeight)

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

Parameters

ImageInterface $image Instance of Image.
int $newWidth Width in pixels.
int $newHeight Height in pixels.

Return Value

EditorInterface An instance of Editor.

at line line 469
EditorInterface resizeExactHeight(ImageInterface $image, int $newHeight)

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

Parameters

ImageInterface $image Instance of Image.
int $newHeight Height in pixels.

Return Value

EditorInterface An instance of Editor.

at line line 492
EditorInterface resizeExactWidth(ImageInterface $image, int $newWidth)

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

Parameters

ImageInterface $image Instance of Image.
int $newWidth Width in pixels.

Return Value

EditorInterface An instance of Editor.

at line line 516
EditorInterface resizeFill(ImageInterface $image, int $newWidth, int $newHeight)

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

Parameters

ImageInterface $image Instance of Image.
int $newWidth Width in pixels.
int $newHeight Height in pixels.

Return Value

EditorInterface An instance of Editor.

at line line 547
EditorInterface resizeFit(ImageInterface $image, int $newWidth, int $newHeight)

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

Parameters

ImageInterface $image Instance of Image.
int $newWidth Width in pixels.
int $newHeight Width in pixels.

Return Value

EditorInterface An instance of Editor.

at line line 578
EditorInterface rotate(ImageInterface $image, int $angle, Color|null $color = null)

Rotate an image counter-clockwise.

Parameters

ImageInterface $image Instance of Image.
int $angle The angle in degrees.
Color|null $color The Color object containing the background color.

Return Value

EditorInterface An instance of Editor.

at line line 606
EditorInterface save(ImageInterface $image, string $file, null|string $type = null, null|string $quality = null, bool $interlace = false, int $permission = 493)

Save the image to an image format.

Parameters

ImageInterface $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 The image format to use. Can be null, "gif", "png", or "jpeg". If null, an appropriate format will be chosen based on the output file name in $file.
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. Default quality if null is 75.
bool $interlace Set to true for progressive JPEG. Applies to JPEG only. Default false.
int $permission Default permission when creating non-existing target directory. Default is 0755. Note: Its using PHP's octal notation so you must prepend numbers with zero (0).

Return Value

EditorInterface An instance of Editor.

Exceptions

Exception

at line line 668
EditorInterface text(ImageInterface $image, string $text, int $size = 12, int $x, int $y, Color $color = null, string $font = '', int $angle)

Write text to image.

Parameters

ImageInterface $image Instance of Image.
string $text The text to be written.
int $size The font size. Defaults to 12.
int $x The distance from the left edge of the image to the left of the text. Defaults to 0.
int $y The distance from the top edge of the image to the baseline of the text. Defaults to 12 (equal to font size) so that the text is placed within the image.
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.
int $angle Angle of text from 0 - 359. Defaults to 0.

Return Value

EditorInterface An instance of Editor.

Exceptions

Exception