Image
class Image
Constants
| ShrinkOnly |
Prevent from getting resized to a bigger size than the original |
| Stretch |
Resizes to a specified width and height without keeping aspect ratio |
| OrSmaller |
Resizes to fit into a specified width and height and preserves aspect ratio |
| OrBigger |
Resizes while bounding the smaller dimension to the specified width or height and preserves aspect ratio |
| Cover |
Resizes to the smallest possible size to completely cover specified width and height and reserves aspect ratio |
| deprecated SHRINK_ONLY |
|
| deprecated STRETCH |
|
| deprecated FIT |
|
| deprecated FILL |
|
| deprecated EXACT |
|
| deprecated EMPTY_GIF |
|
| JPEG |
image types |
| PNG |
image types |
| GIF |
image types |
| WEBP |
image types |
| AVIF |
image types |
| BMP |
image types |
| EmptyGIF |
|
| private Formats |
|
| private Sentinel |
|
Methods
Returns RGB color (0..255) and transparency (0..127).
Reads an image from a file and returns its type in $type. If $warnings is passed, recoverable decoder warnings are returned in it instead of being raised as a PHP warning.
Reads an image from a string and returns its type in $type. If $warnings is passed, recoverable decoder warnings are returned in it instead of being raised as a PHP warning.
Creates a new true color image of the given dimensions. The default color is black.
Returns the type of image from file.
Returns the type of image from string.
Returns the file extension for the given image type.
Returns the image type for given file extension.
Returns the mime type for the given image type.
Checks whether the given image type is supported by the GD extension.
Returns list of image types supported by the GD extension.
Wraps GD image.
Returns image width.
Returns image height.
Sets image resource.
Returns image GD resource.
Scales an image. Width and height accept pixels or percent.
Calculates dimensions of resized image. Width and height accept pixels or percent.
Crops image. Arguments accepts pixels or percent.
Calculates dimensions of cutout in image. Arguments accepts pixels or percent.
Calculates the bounding box for a TrueType text. Returns keys left, top, width and height.
Draws a rectangle using top-left coordinates and dimensions instead of two corner coordinates.
Draws a filled rectangle using top-left coordinates and dimensions instead of two corner coordinates.
Saves image to the file. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
Outputs image to string. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
Outputs image to string.
Outputs image to browser. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
Call to undefined method.
No description
Prevents serialization.
Resolves a color to a GD color index for the current image.
Details
at line 150
static array
rgb(int $red, int $green, int $blue, int $transparency = 0)
deprecated
deprecated
Returns RGB color (0..255) and transparency (0..127).
at line 168
static Image
fromFile(string $file, int|null $type = null, string|null $warnings = self::Sentinel)
Reads an image from a file and returns its type in $type. If $warnings is passed, recoverable decoder warnings are returned in it instead of being raised as a PHP warning.
at line 187
static Image
fromString(string $s, int|null $type = null, string|null $warnings = self::Sentinel)
Reads an image from a string and returns its type in $type. If $warnings is passed, recoverable decoder warnings are returned in it instead of being raised as a PHP warning.
at line 233
static Image
fromBlank(int $width, int $height, ImageColor|array|null $color = null)
Creates a new true color image of the given dimensions. The default color is black.
at line 257
static int|null
detectTypeFromFile(string $file, mixed $width = null, mixed $height = null)
Returns the type of image from file.
at line 270
static int|null
detectTypeFromString(string $s, mixed $width = null, mixed $height = null)
Returns the type of image from string.
at line 282
static string
typeToExtension(int $type)
Returns the file extension for the given image type.
at line 296
static int
extensionToType(string $extension)
Returns the image type for given file extension.
at line 312
static string
typeToMimeType(int $type)
Returns the mime type for the given image type.
at line 322
static bool
isTypeSupported(int $type)
Checks whether the given image type is supported by the GD extension.
at line 341
static array
getSupportedTypes()
Returns list of image types supported by the GD extension.
at line 359
__construct(GdImage $image)
Wraps GD image.
at line 370
int
getWidth()
Returns image width.
at line 380
int
getHeight()
Returns image height.
at line 389
protected Image
setImageResource(GdImage $image)
Sets image resource.
at line 399
GdImage
getImageResource()
Returns image GD resource.
at line 409
Image
resize(int|string|null $width, int|string|null $height, int $mode = self::OrSmaller)
Scales an image. Width and height accept pixels or percent.
at line 451
static array
calculateSize(int $srcWidth, int $srcHeight, int|string|null $newWidth, int|string|null $newHeight, int $mode = self::OrSmaller)
Calculates dimensions of resized image. Width and height accept pixels or percent.
at line 518
Image
crop(int|string $left, int|string $top, int|string $width, int|string $height)
Crops image. Arguments accepts pixels or percent.
at line 539
static array
calculateCutout(int $srcWidth, int $srcHeight, int|string $left, int|string $top, int|string $newWidth, int|string $newHeight)
Calculates dimensions of cutout in image. Arguments accepts pixels or percent.
at line 572
Image
sharpen()
Sharpens image a little bit.
at line 587
Image
place(Image $image, int|string $left = 0, int|string $top = 0, int $opacity = 100)
Puts another image into this image. Left and top accepts pixels or percent.
at line 644
static array
calculateTextBox(string $text, string $fontFile, float $size, float $angle = 0, array $options = [])
Calculates the bounding box for a TrueType text. Returns keys left, top, width and height.
at line 666
void
rectangleWH(int $x, int $y, int $width, int $height, ImageColor $color)
Draws a rectangle using top-left coordinates and dimensions instead of two corner coordinates.
at line 677
void
filledRectangleWH(int $x, int $y, int $width, int $height, ImageColor $color)
Draws a filled rectangle using top-left coordinates and dimensions instead of two corner coordinates.
at line 690
void
save(string $file, int|null $quality = null, int|null $type = null)
Saves image to the file. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
at line 701
string
toString(int $type = ImageType::JPEG, int|null $quality = null)
Outputs image to string. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
at line 712
string
__toString()
Outputs image to string.
at line 723
void
send(int $type = ImageType::JPEG, int|null $quality = null)
Outputs image to browser. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
at line 766
mixed
__call(string $name, array $args)
Call to undefined method.
at line 790
__clone()
No description
at line 816
array
__serialize()
Prevents serialization.
at line 826
int
resolveColor(ImageColor|array $color)
Resolves a color to a GD color index for the current image.
Traits
Strict class for better experience.