Image
in package
implements
JsonSerializable, Stringable
Class Image.
Table of Contents
Interfaces
- JsonSerializable
- Stringable
Properties
- $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.
Methods
- __construct() : mixed
- Image constructor.
- __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
$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
__toString()
public
__toString() : string
Return values
stringcrop()
Crops the image.
public
crop(int $width, int $height[, int $marginLeft = 0 ][, int $marginTop = 0 ]) : static
Parameters
- $width : int
-
Width in pixels
- $height : int
-
Height in pixels
- $marginLeft : int = 0
-
Margin left in pixels
- $marginTop : int = 0
-
Margin top in pixels
Tags
Return values
staticdestroy()
Destroys the GdImage instance.
public
destroy() : bool
Tags
Return values
boolfilter()
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
Return values
staticflatten()
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
Return values
staticflip()
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
Return values
staticgetDataUrl()
Allow embed the image contents in a document.
public
getDataUrl() : string
Tags
Return values
string —The image "data" URL
getExtension()
Gets the file extension for image type.
public
getExtension() : false|string
Attributes
- #[Pure]
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
Attributes
- #[Pure]
Return values
intgetInstance()
Gets the GdImage instance.
public
getInstance() : GdImage
Attributes
- #[Pure]
Return values
GdImage —GdImage instance
getMime()
Gets the image MIME type.
public
getMime() : string
Attributes
- #[Pure]
Return values
stringgetQuality()
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
Attributes
- #[ArrayShape]
- ['horizontal' => 'int', 'vertical' => 'int']
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
Attributes
- #[Pure]
Return values
intisAcceptable()
Indicates if a given filename has an acceptable image type.
public
static isAcceptable(string $filename) : bool
Parameters
- $filename : string
Return values
booljsonSerialize()
public
jsonSerialize() : string
Return values
stringopacity()
Sets the image opacity level.
public
opacity([int $opacity = 100 ]) : static
Parameters
- $opacity : int = 100
-
Opacity percentage: from 0 to 100
Return values
staticrender()
Renders the image contents.
public
render() : string
Tags
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
Return values
staticsave()
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
boolscale()
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
Return values
staticsend()
Sends the image contents to the output buffer.
public
send() : bool
Return values
boolsetInstance()
Sets the GdImage instance.
public
setInstance(GdImage $instance) : static
Parameters
- $instance : GdImage
-
GdImage instance
Return values
staticsetQuality()
Sets the image quality/compression level.
public
setQuality(int $quality) : static
Parameters
- $quality : int
-
The quality/compression level
Tags
Return values
staticsetResolution()
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
Return values
staticwatermark()
Adds a watermark to the image.
public
watermark(Image $watermark[, int $horizontalPosition = 0 ][, int $verticalPosition = 0 ]) : static
Parameters
- $watermark : Image
-
The image to use as watermark
- $horizontalPosition : int = 0
-
Horizontal position
- $verticalPosition : int = 0
-
Vertical position