PHP Class Grafika\Gd\Editor

Inheritance: implements Grafika\EditorInterface
Datei anzeigen Open project: kosinix/grafika Class Usage Examples

Public Methods

Method Description
apply ( Image &$image, Grafika\FilterInterface $filter ) : Editor Apply a filter to the image. See Filters section for a list of available filters.
blend ( Image &$image1, Image $image2, string $type = 'normal', float $opacity = 1, string $position = 'top-left', integer $offsetX, integer $offsetY ) : Editor Blend two images together with the first image as the base and the second image on top. Supports several blend modes.
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.
crop ( Image &$image, integer $cropWidth, integer $cropHeight, string $position = 'center', integer $offsetX, integer $offsetY ) : Editor Crop the image to the given dimension and position.
draw ( Image &$image, Grafika\DrawingObjectInterface $drawingObject ) Draw a DrawingObject on the image. See Drawing Objects section.
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.
fill ( Image &$image, Color $color, integer $x, integer $y ) : Editor Fill entire image with color.
flatten ( Image &$image ) : Editor Flatten if animated GIF. Do nothing otherwise.
flip ( Image &$image, string $mode ) : Editor Flip or mirrors the image.
free ( Image &$image ) : Editor Free the image clearing resources associated with it.
gdAlpha ( float $alpha ) : integer Convert alpha value of 0 - 1 to GD compatible alpha value of 0 - 127 where 0 is opaque and 127 is transparent
isAvailable ( ) : boolean Checks if the editor is available on the current PHP install.
opacity ( Image &$image, float $opacity ) : Editor Sets the image to the specified opacity level where 1.0 is fully opaque and 0.0 is fully transparent.
open ( Image &$image, string $imageFile ) : Editor Open an image file and assign Image to first parameter.
resize ( Image &$image, integer $newWidth, integer $newHeight, string $mode = 'fit' ) : Editor Wrapper function for the resizeXXX family of functions. Resize image given width, height and mode.
resizeExact ( Image &$image, integer $newWidth, integer $newHeight ) : Editor Resize image to exact dimensions ignoring aspect ratio. Useful if you want to force exact width and height.
resizeExactHeight ( Image &$image, integer $newHeight ) : Editor Resize image to exact height. Width is auto calculated. Useful for creating row of images with the same height.
resizeExactWidth ( Image &$image, integer $newWidth ) : Editor Resize image to exact width. Height is auto calculated. Useful for creating column of images with the same width.
resizeFill ( Image &$image, integer $newWidth, integer $newHeight ) : Editor Resize image to fill all the space in the given dimension. Excess parts are cropped.
resizeFit ( Image &$image, integer $newWidth, integer $newHeight ) : Editor Resize image to fit inside the given dimension. No part of the image is lost.
rotate ( Image &$image, integer $angle, Color | null $color = null ) : Grafika\EditorInterface Rotate an image counter-clockwise.
save ( Image $image, string $file, null | string $type = null, null | string $quality = null, boolean | false $interlace = false, integer $permission = 493 ) : Editor Save the image to an image format.
text ( Image &$image, string $text, integer $size = 12, integer $x, integer $y, Color $color = null, string $font = '', integer $angle ) : Grafika\EditorInterface Write text to image.

Private Methods

Method Description
_blendMultiply ( $canvas, $gd1, $gd2, $loopStartY, $loopEndY, $loopStartX, $loopEndX, $offsetX, $offsetY, $opacity )
_blendOverlay ( $canvas, $gd1, $gd2, $loopStartY, $loopEndY, $loopStartX, $loopEndX, $offsetX, $offsetY, $opacity )
_blendScreen ( $canvas, $gd1, $gd2, $loopStartY, $loopEndY, $loopStartX, $loopEndX, $offsetX, $offsetY, $opacity )
_entropy ( $hist ) : float | integer Calculate entropy based on histogram.
_flip ( Image $image, $mode ) : Image Flips image.
_getImageTypeFromFileName ( integer $imageFile ) : ImageType Get image type base on file extension.
_resize ( Image &$image, integer $newWidth, integer $newHeight, integer $targetX, integer $targetY, integer $srcX, integer $srcY ) Resize helper function.
_smartCrop ( Image $oldImage, $cropW, $cropH ) : array Crop based on entropy.

Method Details

apply() public method

Apply a filter to the image. See Filters section for a list of available filters.
public apply ( Image &$image, Grafika\FilterInterface $filter ) : Editor
$image Image
$filter Grafika\FilterInterface
return Editor

blend() public method

Blend two images together with the first image as the base and the second image on top. Supports several blend modes.
public blend ( Image &$image1, Image $image2, string $type = 'normal', float $opacity = 1, string $position = 'top-left', integer $offsetX, integer $offsetY ) : Editor
$image1 Image The base image.
$image2 Image The image placed on top of the base image.
$type string The blend mode. Can be: normal, multiply, overlay or screen.
$opacity float 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.
$position string 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.
$offsetX integer Number of pixels to add to the X position of $image2.
$offsetY integer Number of pixels to add to the Y position of $image2.
return Editor

compare() public method

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.
public compare ( Grafika\ImageInterface | string $image1, Grafika\ImageInterface | string $image2 ) : integer
$image1 Grafika\ImageInterface | string
$image2 Grafika\ImageInterface | string
return integer Hamming distance. Note: This breaks the chain if you are doing fluent api calls as it does not return an Editor.

crop() public method

Crop the image to the given dimension and position.
public crop ( Image &$image, integer $cropWidth, integer $cropHeight, string $position = 'center', integer $offsetX, integer $offsetY ) : Editor
$image Image
$cropWidth integer Crop width in pixels.
$cropHeight integer Crop Height in pixels.
$position string 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.
$offsetX integer Number of pixels to add to the X position of the crop.
$offsetY integer Number of pixels to add to the Y position of the crop.
return Editor

draw() public method

Draw a DrawingObject on the image. See Drawing Objects section.
public draw ( Image &$image, Grafika\DrawingObjectInterface $drawingObject )
$image Image
$drawingObject Grafika\DrawingObjectInterface

equal() public method

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.
public equal ( string | Grafika\ImageInterface $image1, string | Grafika\ImageInterface $image2 ) : boolean
$image1 string | Grafika\ImageInterface Can be an instance of Image or string containing the file system path to image.
$image2 string | Grafika\ImageInterface Can be an instance of Image or string containing the file system path to image.
return 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() public method

Fill entire image with color.
public fill ( Image &$image, Color $color, integer $x, integer $y ) : Editor
$image Image
$color Grafika\Color Color object
$x integer X-coordinate of start point
$y integer Y-coordinate of start point
return Editor

flatten() public method

Flatten if animated GIF. Do nothing otherwise.
public flatten ( Image &$image ) : Editor
$image Image
return Editor

flip() public method

Flip or mirrors the image.
public flip ( Image &$image, string $mode ) : Editor
$image Image
$mode string The type of flip: 'h' for horizontal flip or 'v' for vertical.
return Editor

free() public method

Free the image clearing resources associated with it.
public free ( Image &$image ) : Editor
$image Image
return Editor

gdAlpha() public static method

Convert alpha value of 0 - 1 to GD compatible alpha value of 0 - 127 where 0 is opaque and 127 is transparent
public static gdAlpha ( float $alpha ) : integer
$alpha float Alpha value of 0 - 1. Example: 0, 0.60, 0.9, 1
return integer

isAvailable() public method

Checks if the editor is available on the current PHP install.
public isAvailable ( ) : boolean
return boolean True if available false if not.

opacity() public method

Warning: This function loops thru each pixel manually which can be slow. Use sparingly.
public opacity ( Image &$image, float $opacity ) : Editor
$image Image
$opacity float
return Editor

open() public method

Open an image file and assign Image to first parameter.
public open ( Image &$image, string $imageFile ) : Editor
$image Image
$imageFile string
return Editor

resize() public method

Wrapper function for the resizeXXX family of functions. Resize image given width, height and mode.
public resize ( Image &$image, integer $newWidth, integer $newHeight, string $mode = 'fit' ) : Editor
$image Image
$newWidth integer Width in pixels.
$newHeight integer Height in pixels.
$mode string Resize mode. Possible values: "exact", "exactHeight", "exactWidth", "fill", "fit".
return Editor

resizeExact() public method

Resize image to exact dimensions ignoring aspect ratio. Useful if you want to force exact width and height.
public resizeExact ( Image &$image, integer $newWidth, integer $newHeight ) : Editor
$image Image
$newWidth integer Width in pixels.
$newHeight integer Height in pixels.
return Editor

resizeExactHeight() public method

Resize image to exact height. Width is auto calculated. Useful for creating row of images with the same height.
public resizeExactHeight ( Image &$image, integer $newHeight ) : Editor
$image Image
$newHeight integer Height in pixels.
return Editor

resizeExactWidth() public method

Resize image to exact width. Height is auto calculated. Useful for creating column of images with the same width.
public resizeExactWidth ( Image &$image, integer $newWidth ) : Editor
$image Image
$newWidth integer Width in pixels.
return Editor

resizeFill() public method

Resize image to fill all the space in the given dimension. Excess parts are cropped.
public resizeFill ( Image &$image, integer $newWidth, integer $newHeight ) : Editor
$image Image
$newWidth integer Width in pixels.
$newHeight integer Height in pixels.
return Editor

resizeFit() public method

Resize image to fit inside the given dimension. No part of the image is lost.
public resizeFit ( Image &$image, integer $newWidth, integer $newHeight ) : Editor
$image Image
$newWidth integer Width in pixels.
$newHeight integer Height in pixels.
return Editor

rotate() public method

Rotate an image counter-clockwise.
public rotate ( Image &$image, integer $angle, Color | null $color = null ) : Grafika\EditorInterface
$image Image
$angle integer The angle in degrees.
$color Grafika\Color | null The Color object containing the background color.
return Grafika\EditorInterface An instance of image editor.

save() public method

Save the image to an image format.
public save ( Image $image, string $file, null | string $type = null, null | string $quality = null, boolean | false $interlace = false, integer $permission = 493 ) : Editor
$image Image
$file string File path where to save the image.
$type null | string Type of image. Can be null, "GIF", "PNG", or "JPEG".
$quality null | string 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.
$interlace boolean | false Set to true for progressive JPEG. Applies to JPEG only.
$permission integer Default permission when creating non-existing target directory.
return Editor

text() public method

Write text to image.
public text ( Image &$image, string $text, integer $size = 12, integer $x, integer $y, Color $color = null, string $font = '', integer $angle ) : Grafika\EditorInterface
$image Image
$text string The text to be written.
$size integer The font size. Defaults to 12.
$x integer The distance from the left edge of the image to the left of the text. Defaults to 0.
$y integer 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.
$color Grafika\Color The Color object. Default text color is black.
$font string Full path to font file. If blank, will default to Liberation Sans font.
$angle integer Angle of text from 0 - 359. Defaults to 0.
return Grafika\EditorInterface