GdAdapter
extends Adapter
in package
Image processing adapter for PHP's libGD
Table of Contents
Properties
- $extension : string
- $height : int
- $image : resource
- $imagepath : string
- $options : array<string|int, mixed>
- $width : int
Methods
- __construct() : mixed
- New Slika Adapter
- __destruct() : mixed
- Clean up
- autorotate() : Adapter
- Rote the image based on the rotation exif tag
- crop() : Adapter
- Resize to the given dimension, cropping the image as needed
- resize() : Adapter
- Resize to make image fit the given dimension (maintaining the aspect ratio)
- rotate() : Adapter
- Rotate and/or flip the image
- save() : void
- Save the new file
- boundingBox() : array<string|int, mixed>
- Calculate new size
- cleanDimension() : int
- Ensure the given Dimension is a proper pixel value
- createImage() : resource
- Creates a new blank image to which we can copy
- cropPosition() : array<string|int, mixed>
- Calculates crop position
- keepGifTransparency() : void
- Copy transparency from gif to gif
- loadImage() : resource
- Initialize libGD on the given image
- resizeOperation() : mixed
- resize or crop images using PHP's libGD support
Properties
$extension
protected
string
$extension
the extension of the file we're working with
$height
protected
int
$height
= 0
height of the current image
$image
protected
resource
$image
libGD image
$imagepath
protected
string
$imagepath
path to the image
$options
protected
array<string|int, mixed>
$options
Adapter Options
$width
protected
int
$width
= 0
width of the current image
Methods
__construct()
New Slika Adapter
public
__construct(mixed $imagepath[, mixed $options = [] ]) : mixed
Parameters
- $imagepath : mixed
-
path to the original image
- $options : mixed = []
-
set options
Tags
__destruct()
Clean up
public
__destruct() : mixed
autorotate()
Rote the image based on the rotation exif tag
public
autorotate() : Adapter
Tags
Return values
Adaptercrop()
Resize to the given dimension, cropping the image as needed
public
crop(mixed $width, mixed $height) : Adapter
Parameters
- $width : mixed
-
in pixels or %
- $height : mixed
-
in pixels or %
Tags
Return values
Adapterresize()
Resize to make image fit the given dimension (maintaining the aspect ratio)
public
resize(mixed $width, mixed $height) : Adapter
Parameters
- $width : mixed
-
in pixels or %
- $height : mixed
-
in pixels or %
Tags
Return values
Adapterrotate()
Rotate and/or flip the image
public
rotate(mixed $orientation) : Adapter
Parameters
- $orientation : mixed
-
Exif rotation flags
Tags
Return values
Adaptersave()
Save the new file
public
save(mixed $path[, mixed $extension = '' ]) : void
Parameters
- $path : mixed
- $extension : mixed = ''
-
The type of image to save, empty for original
Tags
boundingBox()
Calculate new size
protected
boundingBox(int $width, int $height) : array<string|int, mixed>
If widht and height are given, the new size will be fit within this bounding box. If only one value is given the other is adjusted to match according to the aspect ratio
Parameters
- $width : int
-
width of the bounding box
- $height : int
-
height of the bounding box
Tags
Return values
array<string|int, mixed> —(width, height)
cleanDimension()
Ensure the given Dimension is a proper pixel value
protected
cleanDimension(int|string $dim, int $orig) : int
When a percentage is given, the value is calculated based on the given original dimension
Parameters
- $dim : int|string
-
New Dimension
- $orig : int
-
Original dimension
Return values
intcreateImage()
Creates a new blank image to which we can copy
protected
createImage(int $width, int $height) : resource
Tries to set up alpha/transparency stuff correctly
Parameters
- $width : int
- $height : int
Tags
Return values
resourcecropPosition()
Calculates crop position
protected
cropPosition(int $width, int $height) : array<string|int, mixed>
Given the wanted final size, this calculates which exact area needs to be cut from the original image to be then resized to the wanted dimensions.
Parameters
- $width : int
- $height : int
Tags
Return values
array<string|int, mixed> —(cropWidth, cropHeight, offsetX, offsetY)
keepGifTransparency()
Copy transparency from gif to gif
protected
keepGifTransparency(resource $image, resource $canvas) : void
If no transparency is found or the PHP does not support it, the canvas is filled with white
Parameters
- $image : resource
-
Original image
- $canvas : resource
-
New, empty image
loadImage()
Initialize libGD on the given image
protected
loadImage(string $path) : resource
Parameters
- $path : string
Tags
Return values
resourceresizeOperation()
resize or crop images using PHP's libGD support
protected
resizeOperation(int $toWidth, int $toHeight[, int $offsetX = 0 ][, int $offsetY = 0 ]) : mixed
Parameters
- $toWidth : int
-
desired width
- $toHeight : int
-
desired height
- $offsetX : int = 0
-
offset of crop centre
- $offsetY : int = 0
-
offset of crop centre