class Image

Image manipulation class.

Constants

RESIZE_IGNORE

Resizing constraint.

RESIZE_AUTO

Resizing constraint.

RESIZE_WIDTH

Resizing constraint.

RESIZE_HEIGHT

Resizing constraint.

WATERMARK_TOP_LEFT

Watermark position.

WATERMARK_TOP_RIGHT

Watermark position.

WATERMARK_BOTTOM_LEFT

Watermark position.

WATERMARK_BOTTOM_RIGHT

Watermark position.

WATERMARK_CENTER

Watermark position.

FLIP_VERTICAL

Flip direction.

FLIP_HORIZONTAL

Flip direction.

Properties

protected ProcessorInterface $processor Processor instance.
protected string $image Path to image file.

Methods

__construct(string $image, ProcessorInterface $processor)

Constructor.

int
normalizeImageQuality(int $quality)

Makes sure that the quality is between 1 and 100.

snapshot()

Creates a snapshot of the image.

restore()

Retstores the 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 $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)

Colorizes 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 = null, int $quality = 95)

Saves image to file.

Details

at line 125
__construct(string $image, ProcessorInterface $processor)

Constructor.

Parameters

string $image Path to image file
ProcessorInterface $processor Processor instance

Exceptions

RuntimeException

at line 149
protected int normalizeImageQuality(int $quality)

Makes sure that the quality is between 1 and 100.

Parameters

int $quality Image quality

Return Value

int

at line 157
snapshot()

Creates a snapshot of the image.

at line 165
restore()

Retstores the image snapshot.

at line 175
int getWidth()

Returns the image width in pixels.

Return Value

int

at line 185
int getHeight()

Returns the image height in pixels.

Return Value

int

at line 195
array getDimensions()

Returns an array containing the image dimensions in pixels.

Return Value

array

at line 206
Image rotate(int $degrees)

Rotates the image using the given angle in degrees.

Parameters

int $degrees Degrees to rotate the image

Return Value

Image

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

Resizes the image to the chosen size.

Parameters

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

Return Value

Image

at line 237
Image 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

Return Value

Image

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

Flips the image.

Parameters

int $direction Direction to flip the image

Return Value

Image

at line 266
Image 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

Return Value

Image

Exceptions

RuntimeException

at line 292
Image brightness(int $level = 50)

Adjust image brightness.

Parameters

int $level Brightness level (-100 to 100)

Return Value

Image

at line 310
Image greyscale()

Converts image to greyscale.

Return Value

Image

at line 322
Image sepia()

Converts image to sepia.

Return Value

Image

at line 334
Image bitonal()

Converts image to bitonal.

Return Value

Image

at line 347
Image colorize(string $color)

Colorizes the image.

Parameters

string $color Hex code for the color

Return Value

Image

at line 357
sharpen()

Sharpens the image.

at line 370
Image pixelate(int $pixelSize = 10)

Pixelates the image.

Parameters

int $pixelSize Pixel size

Return Value

Image

at line 382
Image negate()

Negates the image.

Return Value

Image

at line 396
Image 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

Return Value

Image

at line 410
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 422
save(string $file = null, int $quality = 95)

Saves image to file.

Parameters

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

Exceptions

RuntimeException