PHP Class Grafika\Imagick\Editor

Inheritance: implements Grafika\EditorInterface
Afficher le fichier Open project: kosinix/grafika Class Usage Examples

Méthodes publiques

Méthode 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 ) : self Fill entire image with color.
flatten ( Image &$image ) : self 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.
isAvailable ( ) : boolean Checks if the editor is available on the current PHP install.
opacity ( 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.
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 ) : self Resize image to exact dimensions ignoring aspect ratio. Useful if you want to force exact width and height.
resizeExactHeight ( Image &$image, integer $newHeight ) : self Resize image to exact height. Width is auto calculated. Useful for creating row of images with the same height.
resizeExactWidth ( Image &$image, integer $newWidth ) : self 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 ) : self Resize image to fill all the space in the given dimension. Excess parts are cropped.
resizeFit ( Image &$image, integer $newWidth, integer $newHeight ) : self 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

Méthode Description
_entropy ( array $hist ) : float | integer Calculate entropy based on histogram.
_getImageTypeFromFileName ( integer $imageFile ) : ImageType Get image type base on file extension.
_resize ( Image &$image, integer $newWidth, integer $newHeight ) : self Resize helper function.
_smartCrop ( Image $oldImage, $cropW, $cropH ) : array Crop based on entropy.

Method Details

apply() public méthode

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
Résultat Editor

blend() public méthode

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.
Résultat Editor

compare() public méthode

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
Résultat integer Hamming distance. Note: This breaks the chain if you are doing fluent api calls as it does not return an Editor.

crop() public méthode

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.
Résultat Editor

draw() public méthode

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

equal() public méthode

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.
Résultat 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 méthode

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

flatten() public méthode

Flatten if animated GIF. Do nothing otherwise.
public flatten ( Image &$image ) : self
$image Image
Résultat self

flip() public méthode

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.
Résultat Editor

free() public méthode

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

isAvailable() public méthode

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

opacity() public méthode

Sets the image to the specified opacity level where 1.0 is fully opaque and 0.0 is fully transparent.
public opacity ( Image &$image, float $opacity ) : self
$image Image
$opacity float
Résultat self

open() public méthode

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

resize() public méthode

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".
Résultat Editor

resizeExact() public méthode

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 ) : self
$image Image
$newWidth integer Width in pixels.
$newHeight integer Height in pixels.
Résultat self

resizeExactHeight() public méthode

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 ) : self
$image Image
$newHeight integer Height in pixels.
Résultat self

resizeExactWidth() public méthode

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 ) : self
$image Image
$newWidth integer Width in pixels.
Résultat self

resizeFill() public méthode

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

resizeFit() public méthode

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

rotate() public méthode

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.
Résultat Grafika\EditorInterface An instance of image editor.

save() public méthode

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.
Résultat Editor

text() public méthode

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.
Résultat Grafika\EditorInterface