\GrafikaEditorInterface

Interface EditorInterface

Summary

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

Methods

apply()

apply(\Grafika\ImageInterface  $image, \Grafika\FilterInterface  $filter) : \Grafika\EditorInterface

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

Parameters

\Grafika\ImageInterface $image

Instance of Image.

\Grafika\FilterInterface $filter

Instance implementing the FilterInterface.

Returns

\Grafika\EditorInterface

An instance of Editor.

blend()

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

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

Parameters

\Grafika\ImageInterface $image1

The base image.

\Grafika\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.

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.

Returns

\Grafika\EditorInterface

An instance of Editor.

compare()

compare(string|\Grafika\ImageInterface  $image1, string|\Grafika\ImageInterface  $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

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

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\ImageInterface  $image, integer  $cropWidth, integer  $cropHeight, string  $position = 'center', integer  $offsetX, integer  $offsetY) : \Grafika\EditorInterface

Crop the image to the given dimension and position.

Parameters

\Grafika\ImageInterface $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.

Returns

\Grafika\EditorInterface

An instance of Editor.

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\ImageInterface  $image, \Grafika\Color  $color, integer  $x, integer  $y) : \Grafika\EditorInterface

Fill entire image with color.

Parameters

\Grafika\ImageInterface $image

Instance of Image.

\Grafika\Color $color

An instance of Grafika\Color class.

integer $x

X-coordinate of start point.

integer $y

Y-coordinate of start point.

Returns

\Grafika\EditorInterface

An instance of Editor.

flatten()

flatten(\Grafika\ImageInterface  $image) : \Grafika\EditorInterface

Flatten if animated GIF. Do nothing otherwise.

Parameters

\Grafika\ImageInterface $image

Instance of Image.

Returns

\Grafika\EditorInterface

An instance of Editor.

flip()

flip(\Grafika\ImageInterface  $image, string  $mode) : \Grafika\EditorInterface

Flip an image.

Parameters

\Grafika\ImageInterface $image

Instance of Image.

string $mode

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

Returns

\Grafika\EditorInterface

An instance of Editor.

free()

free(\Grafika\ImageInterface  $image) : \Grafika\EditorInterface

Free the image clearing resources associated with it.

Parameters

\Grafika\ImageInterface $image

Instance of Image.

Returns

\Grafika\EditorInterface

An instance of Editor.

isAvailable()

isAvailable() : boolean

Checks the PHP install if the editor is available.

Returns

boolean —

True if available false if not.

opacity()

opacity(\Grafika\ImageInterface  $image, float  $opacity) : \Grafika\EditorInterface

Change the image opacity.

Parameters

\Grafika\ImageInterface $image

Instance of Image.

float $opacity

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

Returns

\Grafika\EditorInterface

An instance of Editor.

open()

open(\Grafika\ImageInterface  $image, string  $imageFile) : \Grafika\EditorInterface

Open an image file and assign Image to first parameter. Grafika officially supports JPEG, PNG, GIF, and animated GIF. In theory, Grafika can open and edit other image formats as long as they are supported by GD and Imagick but it is currently untested.

Parameters

\Grafika\ImageInterface $image

Instance of Image.

string $imageFile

File system path to image file.

Returns

\Grafika\EditorInterface

An instance of Editor.

resize()

resize(\Grafika\ImageInterface  $image, integer  $newWidth, integer  $newHeight, string  $mode = 'fit') : \Grafika\EditorInterface

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

Parameters

\Grafika\ImageInterface $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".

Returns

\Grafika\EditorInterface

An instance of Editor.

resizeExact()

resizeExact(\Grafika\ImageInterface  $image, integer  $newWidth, integer  $newHeight) : \Grafika\EditorInterface

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

Parameters

\Grafika\ImageInterface $image

Instance of Image.

integer $newWidth

Width in pixels.

integer $newHeight

Height in pixels.

Returns

\Grafika\EditorInterface

An instance of Editor.

resizeExactHeight()

resizeExactHeight(\Grafika\ImageInterface  $image, integer  $newHeight) : \Grafika\EditorInterface

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

Parameters

\Grafika\ImageInterface $image

Instance of Image.

integer $newHeight

Height in pixels.

Returns

\Grafika\EditorInterface

An instance of Editor.

resizeExactWidth()

resizeExactWidth(\Grafika\ImageInterface  $image, integer  $newWidth) : \Grafika\EditorInterface

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

Parameters

\Grafika\ImageInterface $image

Instance of Image.

integer $newWidth

Width in pixels.

Returns

\Grafika\EditorInterface

An instance of Editor.

resizeFill()

resizeFill(\Grafika\ImageInterface  $image, integer  $newWidth, integer  $newHeight) : \Grafika\EditorInterface

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

Parameters

\Grafika\ImageInterface $image

Instance of Image.

integer $newWidth

Width in pixels.

integer $newHeight

Height in pixels.

Returns

\Grafika\EditorInterface

An instance of Editor.

resizeFit()

resizeFit(\Grafika\ImageInterface  $image, integer  $newWidth, integer  $newHeight) : \Grafika\EditorInterface

Resize an image to fit within the given width and height. The re-sized image will not exceed the given dimension. Useful if you want to preserve the aspect ratio.

Parameters

\Grafika\ImageInterface $image

Instance of Image.

integer $newWidth

Width in pixels.

integer $newHeight

Width in pixels.

Returns

\Grafika\EditorInterface

An instance of Editor.

rotate()

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

Rotate an image counter-clockwise.

Parameters

\Grafika\ImageInterface $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 Editor.

save()

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

Save the image to an image format.

Parameters

\Grafika\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.

boolean $interlace

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

integer $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).

Returns

\Grafika\EditorInterface

An instance of Editor.

text()

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

Write text to image.

Parameters

\Grafika\ImageInterface $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 baseline 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

An instance of Editor.