ImageHandlerInterface
in
Expected behavior of an Image handler
Table of Contents
Methods
- convert() : $this
- Changes the stored image type to indicate the new file format to use when saving.
- crop() : $this
- Crops the image to the desired height and width. If one of the height/width values is not provided, that value will be set the appropriate value based on offsets and image dimensions.
- fit() : $this
- Combine cropping and resizing into a single command.
- flatten() : $this
- Flattens transparencies, default white background
- flip() : $this
- Flip an image horizontally or vertically
- getEXIF() : mixed
- Retrieve the EXIF information from the image, if possible. Returns an array of the information, or null if nothing can be found.
- reorient() : ImageHandlerInterface
- Reads the EXIF information from the image and modifies the orientation so that displays correctly in the browser.
- resize() : $this
- Resize the image
- rotate() : $this
- Rotates the image on the current canvas.
- save() : bool
- Saves any changes that have been made to file.
- text() : $this
- Overlays a string of text over the image.
Methods
convert()
Changes the stored image type to indicate the new file format to use when saving.
public
convert(int $imageType) : $this
Does not touch the actual resource.
Parameters
- $imageType : int
-
A PHP imagetype constant, e.g. https://www.php.net/manual/en/function.image-type-to-mime-type.php
Return values
$thiscrop()
Crops the image to the desired height and width. If one of the height/width values is not provided, that value will be set the appropriate value based on offsets and image dimensions.
public
crop([int|null $width = null ][, int|null $height = null ][, int|null $x = null ][, int|null $y = null ][, bool $maintainRatio = false ][, string $masterDim = 'auto' ]) : $this
Parameters
- $width : int|null = null
- $height : int|null = null
- $x : int|null = null
-
X-axis coord to start cropping from the left of image
- $y : int|null = null
-
Y-axis coord to start cropping from the top of image
- $maintainRatio : bool = false
- $masterDim : string = 'auto'
Return values
$thisfit()
Combine cropping and resizing into a single command.
public
fit(int $width, int $height, string $position) : $this
Supported positions:
- top-left
- top
- top-right
- left
- center
- right
- bottom-left
- bottom
- bottom-right
Parameters
- $width : int
- $height : int
- $position : string
Return values
$thisflatten()
Flattens transparencies, default white background
public
flatten([int $red = 255 ][, int $green = 255 ][, int $blue = 255 ]) : $this
Parameters
- $red : int = 255
- $green : int = 255
- $blue : int = 255
Return values
$thisflip()
Flip an image horizontally or vertically
public
flip([string $dir = 'vertical' ]) : $this
Parameters
- $dir : string = 'vertical'
-
Direction to flip, either 'vertical' or 'horizontal'
Return values
$thisgetEXIF()
Retrieve the EXIF information from the image, if possible. Returns an array of the information, or null if nothing can be found.
public
getEXIF([string|null $key = null ]) : mixed
Parameters
- $key : string|null = null
-
If specified, will only return this piece of EXIF data.
reorient()
Reads the EXIF information from the image and modifies the orientation so that displays correctly in the browser.
public
reorient() : ImageHandlerInterface
Return values
ImageHandlerInterfaceresize()
Resize the image
public
resize(int $width, int $height[, bool $maintainRatio = false ][, string $masterDim = 'auto' ]) : $this
Parameters
- $width : int
- $height : int
- $maintainRatio : bool = false
-
If true, will get the closest match possible while keeping aspect ratio true.
- $masterDim : string = 'auto'
Return values
$thisrotate()
Rotates the image on the current canvas.
public
rotate(float $angle) : $this
Parameters
- $angle : float
Return values
$thissave()
Saves any changes that have been made to file.
public
save([non-empty-string|null $target = null ][, int $quality = 90 ]) : bool
Example: $image->resize(100, 200, true) ->save($target);
Parameters
- $target : non-empty-string|null = null
-
The path to save the file to.
- $quality : int = 90
Return values
booltext()
Overlays a string of text over the image.
public
text(string $text[, array<string|int, mixed> $options = [] ]) : $this
Valid options:
- color Text Color (hex number)
- shadowColor Color of the shadow (hex number)
- hAlign Horizontal alignment: left, center, right
- vAlign Vertical alignment: top, middle, bottom
- hOffset
- vOffset
- fontPath
- fontSize
- shadowOffset
Parameters
- $text : string
- $options : array<string|int, mixed> = []