Image
class Image
Basic manipulation with images. Supported types are JPEG, PNG, GIF, WEBP, AVIF and BMP.
$image = Image::fromFile('nette.jpg');
$image->resize(150, 100);
$image->sharpen();
$image->send();
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 |
|
Properties
positive-int read-only | $width | ||
positive-int read-only | $height | ||
GdImage read-only | $imageResource |
Methods
Returns RGB color (0..255) and transparency (0..127).
Reads an image from a file and returns its type in $type.
Reads an image from a string and returns its type in $type.
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.
No description
No description
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.
Draw a filled rectangle.
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.
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
Details
at line 148
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 164
static Image
fromFile(string $file, int|null $type = null)
Reads an image from a file and returns its type in $type.
at line 181
static Image
fromString(string $s, int|null $type = null)
Reads an image from a string and returns its type in $type.
at line 216
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 238
static int|null
detectTypeFromFile(string $file, $width = null, $height = null)
Returns the type of image from file.
at line 249
static int|null
detectTypeFromString(string $s, $width = null, $height = null)
Returns the type of image from string.
at line 261
static string
typeToExtension(int $type)
Returns the file extension for the given image type.
at line 275
static int
extensionToType(string $extension)
Returns the image type for given file extension.
at line 291
static string
typeToMimeType(int $type)
Returns the mime type for the given image type.
at line 300
static bool
isTypeSupported(int $type)
No description
at line 316
static array
getSupportedTypes()
No description
at line 334
__construct(GdImage $image)
Wraps GD image.
at line 345
int
getWidth()
Returns image width.
at line 355
int
getHeight()
Returns image height.
at line 364
protected Image
setImageResource(GdImage $image)
Sets image resource.
at line 374
GdImage
getImageResource()
Returns image GD resource.
at line 384
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 421
static array
calculateSize(int $srcWidth, int $srcHeight, $newWidth, $newHeight, int $mode = self::OrSmaller)
Calculates dimensions of resized image. Width and height accept pixels or percent.
at line 488
Image
crop(int|string $left, int|string $top, int|string $width, int|string $height)
Crops image. Arguments accepts pixels or percent.
at line 508
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 552
Image
sharpen()
Sharpens image a little bit.
at line 567
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 628
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 650
void
rectangleWH(int $x, int $y, int $width, int $height, ImageColor $color)
Draw a rectangle.
at line 661
void
filledRectangleWH(int $x, int $y, int $width, int $height, ImageColor $color)
Draw a filled rectangle.
at line 674
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 685
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 696
string
__toString()
Outputs image to string.
at line 707
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 764
mixed
__call(string $name, array $args)
Call to undefined method.
at line 787
__clone()
No description
at line 812
array
__sleep()
Prevents serialization.
at line 818
int
resolveColor(ImageColor|array $color)
No description
at line 91
Image
affine(array $affine, ?array $clip = null)
No description
at line 91
void
alphaBlending(bool $enable)
No description
at line 91
void
antialias(bool $enable)
No description
at line 91
void
arc(int $centerX, int $centerY, int $width, int $height, int $startAngle, int $endAngle, ImageColor $color)
No description
at line 91
int
colorAllocate(int $red, int $green, int $blue)
No description
at line 91
int
colorAllocateAlpha(int $red, int $green, int $blue, int $alpha)
No description
at line 91
int
colorAt(int $x, int $y)
No description
at line 91
int
colorClosest(int $red, int $green, int $blue)
No description
at line 91
int
colorClosestAlpha(int $red, int $green, int $blue, int $alpha)
No description
at line 91
int
colorClosestHWB(int $red, int $green, int $blue)
No description
at line 91
void
colorDeallocate(int $color)
No description
at line 91
int
colorExact(int $red, int $green, int $blue)
No description
at line 91
int
colorExactAlpha(int $red, int $green, int $blue, int $alpha)
No description
at line 91
void
colorMatch(Image $image2)
No description
at line 91
int
colorResolve(int $red, int $green, int $blue)
No description
at line 91
int
colorResolveAlpha(int $red, int $green, int $blue, int $alpha)
No description
at line 91
void
colorSet(int $index, int $red, int $green, int $blue, int $alpha)
No description
at line 91
array
colorsForIndex(int $color)
No description
at line 91
int
colorsTotal()
No description
at line 91
int
colorTransparent(?int $color = null)
No description
at line 91
void
convolution(array $matrix, float $div, float $offset)
No description
at line 91
void
copy(Image $src, int $dstX, int $dstY, int $srcX, int $srcY, int $srcW, int $srcH)
No description
at line 91
void
copyMerge(Image $src, int $dstX, int $dstY, int $srcX, int $srcY, int $srcW, int $srcH, int $pct)
No description
at line 91
void
copyMergeGray(Image $src, int $dstX, int $dstY, int $srcX, int $srcY, int $srcW, int $srcH, int $pct)
No description
at line 91
void
copyResampled(Image $src, int $dstX, int $dstY, int $srcX, int $srcY, int $dstW, int $dstH, int $srcW, int $srcH)
No description
at line 91
void
copyResized(Image $src, int $dstX, int $dstY, int $srcX, int $srcY, int $dstW, int $dstH, int $srcW, int $srcH)
No description
at line 91
Image
cropAuto(int $mode = IMG_CROP_DEFAULT, float $threshold = .5, ImageColor $color = null)
No description
at line 91
void
ellipse(int $centerX, int $centerY, int $width, int $height, ImageColor $color)
No description
at line 91
void
fill(int $x, int $y, ImageColor $color)
No description
at line 91
void
filledArc(int $centerX, int $centerY, int $width, int $height, int $startAngle, int $endAngle, ImageColor $color, int $style)
No description
at line 91
void
filledEllipse(int $centerX, int $centerY, int $width, int $height, ImageColor $color)
No description
at line 91
void
filledPolygon(array $points, ImageColor $color)
No description
at line 91
void
filledRectangle(int $x1, int $y1, int $x2, int $y2, ImageColor $color)
No description
at line 91
void
fillToBorder(int $x, int $y, ImageColor $borderColor, ImageColor $color)
No description
at line 91
void
filter(int $filter, mixed $args)
No description
at line 91
void
flip(int $mode)
No description
at line 91
array
ftText(float $size, float $angle, int $x, int $y, ImageColor $color, string $fontFile, string $text, array $options = [])
No description
at line 91
void
gammaCorrect(float $inputgamma, float $outputgamma)
No description
at line 91
array
getClip()
No description
at line 91
int
getInterpolation()
No description
at line 91
int
interlace(?bool $enable = null)
No description
at line 91
bool
isTrueColor()
No description
at line 91
void
layerEffect(int $effect)
No description
at line 91
void
line(int $x1, int $y1, int $x2, int $y2, ImageColor $color)
No description
at line 91
void
openPolygon(array $points, ImageColor $color)
No description
at line 91
void
paletteCopy(Image $source)
No description
at line 91
void
paletteToTrueColor()
No description
at line 91
void
polygon(array $points, ImageColor $color)
No description
at line 91
void
rectangle(int $x1, int $y1, int $x2, int $y2, ImageColor $color)
No description
at line 91
mixed
resolution(?int $resolutionX = null, ?int $resolutionY = null)
No description
at line 91
Image
rotate(float $angle, ImageColor $backgroundColor)
No description
at line 91
void
saveAlpha(bool $enable)
No description
at line 91
Image
scale(int $newWidth, int $newHeight = -1, int $mode = IMG_BILINEAR_FIXED)
No description
at line 91
void
setBrush(Image $brush)
No description
at line 91
void
setClip(int $x1, int $y1, int $x2, int $y2)
No description
at line 91
void
setInterpolation(int $method = IMG_BILINEAR_FIXED)
No description
at line 91
void
setPixel(int $x, int $y, ImageColor $color)
No description
at line 91
void
setStyle(array $style)
No description
at line 91
void
setThickness(int $thickness)
No description
at line 91
void
setTile(Image $tile)
No description
at line 91
void
trueColorToPalette(bool $dither, int $ncolors)
No description
at line 91
array
ttfText(float $size, float $angle, int $x, int $y, ImageColor $color, string $fontfile, string $text, array $options = [])
No description
Traits
Strict class for better experience.