Aplus Framework Docs

Image
in package
implements JsonSerializable, Stringable

Class Image.

Interfaces, Classes, Traits and Enums

JsonSerializable
Stringable

Table of Contents

$filename  : string
Path to the image file.
$instance  : GdImage
GdImage instance.
$mime  : string
MIME type.
$quality  : int|null
The image quality/compression level.
$type  : int
Image type. One of IMAGETYPE_* constants.
__construct()  : mixed
Image constructor.
__destruct()  : mixed
__toString()  : string
crop()  : static
Crops the image.
destroy()  : bool
Destroys the GdImage instance.
filter()  : static
Applies a filter to the image.
flatten()  : static
Flattens the image.
flip()  : static
Flips the image.
getDataUrl()  : string
Allow embed the image contents in a document.
getExtension()  : false|string
Gets the file extension for image type.
getHeight()  : int
Gets the image height.
getInstance()  : GdImage
Gets the GdImage instance.
getMime()  : string
Gets the image MIME type.
getQuality()  : int|null
Gets the image quality/compression level.
getResolution()  : array<string, int>
Gets the image resolution.
getWidth()  : int
Gets the image width.
isAcceptable()  : bool
Indicates if a given filename has an acceptable image type.
jsonSerialize()  : string
opacity()  : static
Sets the image opacity level.
render()  : string
Renders the image contents.
rotate()  : static
Rotates the image with a given angle.
save()  : bool
Saves the image contents to a given filename.
scale()  : static
Scales the image.
send()  : bool
Sends the image contents to the output buffer.
setInstance()  : static
Sets the GdImage instance.
setQuality()  : static
Sets the image quality/compression level.
setResolution()  : static
Sets the image resolution.
watermark()  : static
Adds a watermark to the image.

Properties

$filename

Path to the image file.

protected string $filename

$instance

GdImage instance.

protected GdImage $instance

$mime

MIME type.

protected string $mime

$quality

The image quality/compression level.

protected int|null $quality = null

0 to 9 on PNG, default is 6. 0 to 100 on JPEG, default is 75. Null to update to the default when getQuality is called.

Tags
see
Image::getQuality()

$type

Image type. One of IMAGETYPE_* constants.

protected int $type

Methods

__construct()

Image constructor.

public __construct(string $filename) : mixed
Parameters
$filename : string

Path to the image file. Acceptable types are: GIF, JPEG and PNG

Tags
throws
InvalidArgumentException

for invalid file

throws
RuntimeException

for unsupported image type of could not get image info

Return values
mixed

__destruct()

public __destruct() : mixed
Return values
mixed

__toString()

public __toString() : string
Return values
string

crop()

Crops the image.

public crop(int $width, int $height, int $marginLeft, int $marginTop) : static
Parameters
$width : int

Width in pixels

$height : int

Height in pixels

$marginLeft : int

Margin left in pixels

$marginTop : int

Margin top in pixels

Tags
throws
RuntimeException

for image could not to crop

Return values
static

destroy()

Destroys the GdImage instance.

public destroy() : bool
Return values
bool

filter()

Applies a filter to the image.

public filter(int $type, int ...$arguments) : static
Parameters
$type : int

IMG_FILTER_* constants

$arguments : int

Arguments for the filter type

Tags
see
https://www.php.net/manual/en/function.imagefilter.php
throws
RuntimeException

for image could not apply the filter

Return values
static

flatten()

Flattens the image.

public flatten([int $red = 255 ][, int $green = 255 ][, int $blue = 255 ]) : static

Replaces transparency with an RGB color.

Parameters
$red : int = 255
$green : int = 255
$blue : int = 255
Tags
throws
RuntimeException

for could not create a true color image, could not allocate a color or image could not to flatten

Return values
static

flip()

Flips the image.

public flip([string $direction = 'horizontal' ]) : static
Parameters
$direction : string = 'horizontal'

Allowed values are: h or horizontal. v or vertical. b or both.

Tags
throws
InvalidArgumentException

for invalid image flip direction

throws
RuntimeException

for image could not to flip

Return values
static

getExtension()

Gets the file extension for image type.

public getExtension() : false|string
Return values
false|string

a string with the extension corresponding to the given image type or false on fail

getHeight()

Gets the image height.

public getHeight() : int
Return values
int

getInstance()

Gets the GdImage instance.

public getInstance() : GdImage
Return values
GdImage

GdImage instance

getMime()

Gets the image MIME type.

public getMime() : string
Return values
string

getQuality()

Gets the image quality/compression level.

public getQuality() : int|null
Return values
int|null

An integer for PNG and JPEG types or null for GIF

getResolution()

Gets the image resolution.

public getResolution() : array<string, int>
Tags
throws
RuntimeException

for image could not get resolution

Return values
array<string, int>

Returns an array containing two keys, horizontal and vertical, with integers as values

getWidth()

Gets the image width.

public getWidth() : int
Return values
int

isAcceptable()

Indicates if a given filename has an acceptable image type.

public static isAcceptable(string $filename) : bool
Parameters
$filename : string
Return values
bool

jsonSerialize()

public jsonSerialize() : string
Return values
string

opacity()

Sets the image opacity level.

public opacity([int $opacity = 100 ]) : static
Parameters
$opacity : int = 100

Opacity percentage: from 0 to 100

Return values
static

render()

Renders the image contents.

public render() : string
Tags
throws
RuntimeException

for image could not be rendered

Return values
string

The image contents

rotate()

Rotates the image with a given angle.

public rotate(float $angle) : static
Parameters
$angle : float

Rotation angle, in degrees. Clockwise direction.

Tags
throws
RuntimeException

for image could not allocate a color or could not rotate

Return values
static

save()

Saves the image contents to a given filename.

public save([string|null $filename = null ]) : bool
Parameters
$filename : string|null = null

Optional filename or null to use the original

Return values
bool

scale()

Scales the image.

public scale(int $width[, int $height = -1 ]) : static
Parameters
$width : int

Width in pixels

$height : int = -1

Height in pixels. Use -1 to use a proportional height based on the width.

Tags
throws
RuntimeException

for image could not to scale

Return values
static

send()

Sends the image contents to the output buffer.

public send() : bool
Return values
bool

setInstance()

Sets the GdImage instance.

public setInstance(GdImage $instance) : static
Parameters
$instance : GdImage

GdImage instance

Return values
static

setQuality()

Sets the image quality/compression level.

public setQuality(int $quality) : static
Parameters
$quality : int

The quality/compression level

Tags
throws
LogicException

when trying to set a quality value for a GIF image

throws
InvalidArgumentException

if the image type is PNG and the value is not between 0 and 9 or if the image type is JPEG and the value is not between 0 and 100

Return values
static

setResolution()

Sets the image resolution.

public setResolution([int $horizontal = 96 ][, int $vertical = 96 ]) : static
Parameters
$horizontal : int = 96

The horizontal resolution in DPI

$vertical : int = 96

The vertical resolution in DPI

Tags
throws
RuntimeException

for image could not to set resolution

Return values
static

watermark()

Adds a watermark to the image.

public watermark(Image $watermark, int $horizontalPosition, int $verticalPosition) : static
Parameters
$watermark : Image

The image to use as watermark

$horizontalPosition : int

Horizontal position

$verticalPosition : int

Vertical position

Tags
throws
RuntimeException

for image could not to create watermark

Return values
static

Search results