class GD implements ProcessorInterface

GD processor.

Traits

Calculate new image dimensions.

Properties

protected resource $image Image resource.
protected GdImage|resource|null $snapshot Image resource.
protected array $imageInfo Image info.
protected bool $hasFilters Do we have the imagefilter function?

Methods

array
calculateNewDimensions(int $width, int|null $height, int $oldWidth, int $oldHeight, int $aspectRatio)

Calculates new image dimensions.

__construct()

Constructor.

__destruct()

Destructor.

array
getImageInfo(string $file)

Collects information about the image.

resource
createImageResource(string $image, array $imageInfo)

Creates an image resource that we can work with.

array
hexToRgb(string $hex)

Converts HEX value to an RGB array.

open(string $image)

Opens the image we want to work with.

snapshot()

Creates a snapshot of the image resource.

restore()

Restores an image snapshot.

int
getWidth()

Returns the image width in pixels.

int
getHeight()

Returns the image height in pixels.

array
getDimensions()

Returns an array containing the image dimensions in pixels.

rotate(int $degrees)

Rotates the image using the given angle in degrees.

resize(int $width, int|null $height = null, int $aspectRatio = Image::RESIZE_IGNORE)

Resizes the image to the chosen size.

crop(int $width, int $height, int $x, int $y)

Crops the image.

flip(int $direction = Image::FLIP_HORIZONTAL)

Flips the image.

watermark(string $file, int $position = Image::WATERMARK_TOP_LEFT, int $opacity = 100)

Adds a watermark to the image.

brightness(int $level = 50)

Adjust image brightness.

greyscale()

Converts image to greyscale.

sepia()

Converts image to sepia.

bitonal()

Converts image to bitonal.

colorize(string $color)

Colorize the image.

sharpen()

Sharpens the image.

pixelate(int $pixelSize = 10)

Pixelates the image.

negate()

Negates the image.

border(string $color = '#000', int $thickness = 5)

Adds a border to the image.

string
getImageBlob(string $type = null, int $quality = 95)

Returns a string containing the image.

save(string $file, int $quality = 95)

Saves image to file.

Details

protected array calculateNewDimensions(int $width, int|null $height, int $oldWidth, int $oldHeight, int $aspectRatio)

Calculates new image dimensions.

Parameters

int $width Desired image width
int|null $height Desired image height
int $oldWidth Old image width
int $oldHeight Old image height
int $aspectRatio Aspect ratio

Return Value

array

at line 101
__construct()

Constructor.

at line 109
__destruct()

Destructor.

at line 128
protected array getImageInfo(string $file)

Collects information about the image.

Parameters

string $file Path to image file

Return Value

array

at line 147
protected resource createImageResource(string $image, array $imageInfo)

Creates an image resource that we can work with.

Parameters

string $image Path to image file
array $imageInfo Image info

Return Value

resource

at line 168
protected array hexToRgb(string $hex)

Converts HEX value to an RGB array.

Parameters

string $hex HEX value

Return Value

array

at line 196
open(string $image)

Opens the image we want to work with.

Parameters

string $image Path to image file

at line 206
snapshot()

Creates a snapshot of the image resource.

at line 219
restore()

Restores an image snapshot.

at line 234
int getWidth()

Returns the image width in pixels.

Return Value

int

at line 242
int getHeight()

Returns the image height in pixels.

Return Value

int

at line 250
array getDimensions()

Returns an array containing the image dimensions in pixels.

Return Value

array

at line 258
rotate(int $degrees)

Rotates the image using the given angle in degrees.

Parameters

int $degrees Degrees to rotate the image

at line 286
resize(int $width, int|null $height = null, int $aspectRatio = Image::RESIZE_IGNORE)

Resizes the image to the chosen size.

Parameters

int $width Width of the image
int|null $height Height of the image
int $aspectRatio Aspect ratio

at line 311
crop(int $width, int $height, int $x, int $y)

Crops the image.

Parameters

int $width Width of the crop
int $height Height of the crop
int $x The X coordinate of the cropped region's top left corner
int $y The Y coordinate of the cropped region's top left corner

at line 334
flip(int $direction = Image::FLIP_HORIZONTAL)

Flips the image.

Parameters

int $direction Direction to flip the image

at line 374
watermark(string $file, int $position = Image::WATERMARK_TOP_LEFT, int $opacity = 100)

Adds a watermark to the image.

Parameters

string $file Path to the image file
int $position Position of the watermark
int $opacity Opacity of the watermark in percent

at line 429
brightness(int $level = 50)

Adjust image brightness.

Parameters

int $level Brightness level (-100 to 100)

at line 473
greyscale()

Converts image to greyscale.

at line 520
sepia()

Converts image to sepia.

at line 559
bitonal()

Converts image to bitonal.

at line 601
colorize(string $color)

Colorize the image.

Parameters

string $color Hex value

at line 647
sharpen()

Sharpens the image.

at line 659
pixelate(int $pixelSize = 10)

Pixelates the image.

Parameters

int $pixelSize Pixel size

at line 679
negate()

Negates the image.

at line 711
border(string $color = '#000', int $thickness = 5)

Adds a border to the image.

Parameters

string $color Hex code for the color
int $thickness Thickness of the frame in pixels

at line 740
string getImageBlob(string $type = null, int $quality = 95)

Returns a string containing the image.

Parameters

string $type Image type
int $quality Image quality 1-100

Return Value

string

at line 776
save(string $file, int $quality = 95)

Saves image to file.

Parameters

string $file Path to the image file
int $quality Image quality 1-100