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 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 166
static Image
fromFile(string $file, int|null $type = null)
Reads an image from a file and returns its type in $type.
at line 183
static Image
fromString(string $s, int|null $type = null)
Reads an image from a string and returns its type in $type.
at line 218
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 240
static int|null
detectTypeFromFile(string $file, $width = null, $height = null)
Returns the type of image from file.
at line 251
static int|null
detectTypeFromString(string $s, $width = null, $height = null)
Returns the type of image from string.
at line 263
static string
typeToExtension(int $type)
Returns the file extension for the given image type.
at line 277
static int
extensionToType(string $extension)
Returns the image type for given file extension.
at line 293
static string
typeToMimeType(int $type)
Returns the mime type for the given image type.
at line 302
static bool
isTypeSupported(int $type)
No description
at line 318
static array
getSupportedTypes()
No description
at line 336
__construct(GdImage $image)
Wraps GD image.
at line 347
int
getWidth()
Returns image width.
at line 357
int
getHeight()
Returns image height.
at line 366
protected Image
setImageResource(GdImage $image)
Sets image resource.
at line 376
GdImage
getImageResource()
Returns image GD resource.
at line 386
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 423
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 490
Image
crop(int|string $left, int|string $top, int|string $width, int|string $height)
Crops image. Arguments accepts pixels or percent.
at line 510
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 554
Image
sharpen()
Sharpens image a little bit.
at line 569
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 630
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 652
void
rectangleWH(int $x, int $y, int $width, int $height, ImageColor $color)
Draw a rectangle.
at line 663
void
filledRectangleWH(int $x, int $y, int $width, int $height, ImageColor $color)
Draw a filled rectangle.
at line 676
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 687
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 698
string
__toString()
Outputs image to string.
at line 709
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 751
mixed
__call(string $name, array $args)
Call to undefined method.
at line 774
__clone()
No description
at line 799
array
__sleep()
Prevents serialization.
at line 805
int
resolveColor(ImageColor|array $color)
No description
at line 93
Image
affine(array $affine, ?array $clip = null)
No description
at line 93
void
alphaBlending(bool $enable)
No description
at line 93
void
antialias(bool $enable)
No description
at line 93
void
arc(int $centerX, int $centerY, int $width, int $height, int $startAngle, int $endAngle, ImageColor $color)
No description
at line 93
int
colorAllocate(int $red, int $green, int $blue)
No description
at line 93
int
colorAllocateAlpha(int $red, int $green, int $blue, int $alpha)
No description
at line 93
int
colorAt(int $x, int $y)
No description
at line 93
int
colorClosest(int $red, int $green, int $blue)
No description
at line 93
int
colorClosestAlpha(int $red, int $green, int $blue, int $alpha)
No description
at line 93
int
colorClosestHWB(int $red, int $green, int $blue)
No description
at line 93
void
colorDeallocate(int $color)
No description
at line 93
int
colorExact(int $red, int $green, int $blue)
No description
at line 93
int
colorExactAlpha(int $red, int $green, int $blue, int $alpha)
No description
at line 93
void
colorMatch(Image $image2)
No description
at line 93
int
colorResolve(int $red, int $green, int $blue)
No description
at line 93
int
colorResolveAlpha(int $red, int $green, int $blue, int $alpha)
No description
at line 93
void
colorSet(int $index, int $red, int $green, int $blue, int $alpha)
No description
at line 93
array
colorsForIndex(int $color)
No description
at line 93
int
colorsTotal()
No description
at line 93
int
colorTransparent(?int $color = null)
No description
at line 93
void
convolution(array $matrix, float $div, float $offset)
No description
at line 93
void
copy(Image $src, int $dstX, int $dstY, int $srcX, int $srcY, int $srcW, int $srcH)
No description
at line 93
void
copyMerge(Image $src, int $dstX, int $dstY, int $srcX, int $srcY, int $srcW, int $srcH, int $pct)
No description
at line 93
void
copyMergeGray(Image $src, int $dstX, int $dstY, int $srcX, int $srcY, int $srcW, int $srcH, int $pct)
No description
at line 93
void
copyResampled(Image $src, int $dstX, int $dstY, int $srcX, int $srcY, int $dstW, int $dstH, int $srcW, int $srcH)
No description
at line 93
void
copyResized(Image $src, int $dstX, int $dstY, int $srcX, int $srcY, int $dstW, int $dstH, int $srcW, int $srcH)
No description
at line 93
Image
cropAuto(int $mode = IMG_CROP_DEFAULT, float $threshold = .5, ImageColor $color = null)
No description
at line 93
void
ellipse(int $centerX, int $centerY, int $width, int $height, ImageColor $color)
No description
at line 93
void
fill(int $x, int $y, ImageColor $color)
No description
at line 93
void
filledArc(int $centerX, int $centerY, int $width, int $height, int $startAngle, int $endAngle, ImageColor $color, int $style)
No description
at line 93
void
filledEllipse(int $centerX, int $centerY, int $width, int $height, ImageColor $color)
No description
at line 93
void
filledPolygon(array $points, ImageColor $color)
No description
at line 93
void
filledRectangle(int $x1, int $y1, int $x2, int $y2, ImageColor $color)
No description
at line 93
void
fillToBorder(int $x, int $y, ImageColor $borderColor, ImageColor $color)
No description
at line 93
void
filter(int $filter, mixed $args)
No description
at line 93
void
flip(int $mode)
No description
at line 93
array
ftText(float $size, float $angle, int $x, int $y, ImageColor $color, string $fontFile, string $text, array $options = [])
No description
at line 93
void
gammaCorrect(float $inputgamma, float $outputgamma)
No description
at line 93
array
getClip()
No description
at line 93
int
getInterpolation()
No description
at line 93
int
interlace(?bool $enable = null)
No description
at line 93
bool
isTrueColor()
No description
at line 93
void
layerEffect(int $effect)
No description
at line 93
void
line(int $x1, int $y1, int $x2, int $y2, ImageColor $color)
No description
at line 93
void
openPolygon(array $points, ImageColor $color)
No description
at line 93
void
paletteCopy(Image $source)
No description
at line 93
void
paletteToTrueColor()
No description
at line 93
void
polygon(array $points, ImageColor $color)
No description
at line 93
void
rectangle(int $x1, int $y1, int $x2, int $y2, ImageColor $color)
No description
at line 93
mixed
resolution(?int $resolutionX = null, ?int $resolutionY = null)
No description
at line 93
Image
rotate(float $angle, ImageColor $backgroundColor)
No description
at line 93
void
saveAlpha(bool $enable)
No description
at line 93
Image
scale(int $newWidth, int $newHeight = -1, int $mode = IMG_BILINEAR_FIXED)
No description
at line 93
void
setBrush(Image $brush)
No description
at line 93
void
setClip(int $x1, int $y1, int $x2, int $y2)
No description
at line 93
void
setInterpolation(int $method = IMG_BILINEAR_FIXED)
No description
at line 93
void
setPixel(int $x, int $y, ImageColor $color)
No description
at line 93
void
setStyle(array $style)
No description
at line 93
void
setThickness(int $thickness)
No description
at line 93
void
setTile(Image $tile)
No description
at line 93
void
trueColorToPalette(bool $dither, int $ncolors)
No description
at line 93
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.