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
- 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
createImage()
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