Image
class Image
Basic manipulation with images.
$image = Image::fromFile('nette.jpg');
$image->resize(150, 100);
$image->sharpen();
$image->send();
Constants
SHRINK_ONLY |
resize() only shrinks images |
STRETCH |
resize() will ignore aspect ratio |
FIT |
resize() fits in given area so its dimensions are less than or equal to the required dimensions |
FILL |
resize() fills given area so its dimensions are greater than or equal to the required dimensions |
EXACT |
resize() fills given area exactly |
JPEG |
image types |
PNG |
image types |
GIF |
image types |
WEBP |
image types |
BMP |
image types |
EMPTY_GIF |
|
private FORMATS |
|
Properties
int read-only | $width | ||
int read-only | $height | ||
resource|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 $detectedFormat. Supported types are JPEG, PNG, GIF, WEBP and BMP.
Reads an image from a string and returns its type in $detectedFormat. Supported types are JPEG, PNG, GIF, WEBP and BMP.
Creates a new true color image of the given dimensions. The default color is black.
Returns the file extension for the given Image::XXX
constant.
Returns the mime type for the given Image::XXX
constant.
Wraps GD image.
Returns image width.
Returns image height.
Sets image resource.
Returns image GD resource.
Scales an image.
Calculates dimensions of resized image.
Calculates dimensions of cutout in image.
Saves image to the file. Quality is in the range 0..100 for JPEG (default 85) and WEBP (default 80) and 0..9 for PNG (default 9).
Outputs image to string. Quality is in the range 0..100 for JPEG (default 85) and WEBP (default 80) 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) and WEBP (default 80) 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
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 135
static array
rgb(int $red, int $green, int $blue, int $transparency = 0)
Returns RGB color (0..255) and transparency (0..127).
at line 152
static Image
fromFile(string $file, int $detectedFormat = null)
Reads an image from a file and returns its type in $detectedFormat. Supported types are JPEG, PNG, GIF, WEBP and BMP.
at line 175
static Image
fromString(string $s, int $detectedFormat = null)
Reads an image from a string and returns its type in $detectedFormat. Supported types are JPEG, PNG, GIF, WEBP and BMP.
at line 198
static Image
fromBlank(int $width, int $height, array $color = null)
Creates a new true color image of the given dimensions. The default color is black.
at line 223
static string
typeToExtension(int $type)
Returns the file extension for the given Image::XXX
constant.
at line 235
static string
typeToMimeType(int $type)
Returns the mime type for the given Image::XXX
constant.
at line 245
__construct(resource|GdImage $image)
Wraps GD image.
at line 255
int
getWidth()
Returns image width.
at line 264
int
getHeight()
Returns image height.
at line 275
protected Image
setImageResource(resource|GdImage $image)
Sets image resource.
at line 289
resource|GdImage
getImageResource()
Returns image GD resource.
at line 301
Image
resize(int|string|null $width, int|string|null $height, int $flags = self::FIT)
Scales an image.
at line 338
static array
calculateSize(int $srcWidth, int $srcHeight, int|string|null $newWidth, int|string|null $newHeight, int $flags = self::FIT)
Calculates dimensions of resized image.
at line 410
Image
crop(int|string $left, int|string $top, int|string $width, int|string $height)
Crops image.
at line 433
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.
at line 465
Image
sharpen()
Sharpens image a little bit.
at line 483
Image
place(Image $image, int|string $left = 0, int|string $top = 0, int $opacity = 100)
Puts another image into this image.
at line 543
void
save(string $file, int $quality = null, int $type = null)
Saves image to the file. Quality is in the range 0..100 for JPEG (default 85) and WEBP (default 80) and 0..9 for PNG (default 9).
at line 561
string
toString(int $type = self::JPEG, int $quality = null)
Outputs image to string. Quality is in the range 0..100 for JPEG (default 85) and WEBP (default 80) and 0..9 for PNG (default 9).
at line 572
string
__toString()
Outputs image to string.
at line 590
void
send(int $type = self::JPEG, int $quality = null)
Outputs image to browser. Quality is in the range 0..100 for JPEG (default 85) and WEBP (default 80) and 0..9 for PNG (default 9).
at line 641
mixed
__call(string $name, array $args)
Call to undefined method.
at line 675
__clone()
No description
at line 702
array
__sleep()
Prevents serialization.
at line 97
Image
affine(array $affine, array $clip = null)
No description
at line 97
array
affineMatrixConcat(array $m1, array $m2)
No description
at line 97
array
affineMatrixGet(int $type, mixed $options = null)
No description
at line 97
void
alphaBlending(bool $on)
No description
at line 97
void
antialias(bool $on)
No description
at line 97
void
arc(mixed $x, mixed $y, mixed $w, mixed $h, mixed $start, mixed $end, mixed $color)
No description
at line 97
void
char(int $font, mixed $x, mixed $y, string $char, mixed $color)
No description
at line 97
void
charUp(int $font, mixed $x, mixed $y, string $char, mixed $color)
No description
at line 97
int
colorAllocate(mixed $red, mixed $green, mixed $blue)
No description
at line 97
int
colorAllocateAlpha(mixed $red, mixed $green, mixed $blue, mixed $alpha)
No description
at line 97
int
colorAt(mixed $x, mixed $y)
No description
at line 97
int
colorClosest(mixed $red, mixed $green, mixed $blue)
No description
at line 97
int
colorClosestAlpha(mixed $red, mixed $green, mixed $blue, mixed $alpha)
No description
at line 97
int
colorClosestHWB(mixed $red, mixed $green, mixed $blue)
No description
at line 97
void
colorDeallocate(mixed $color)
No description
at line 97
int
colorExact(mixed $red, mixed $green, mixed $blue)
No description
at line 97
int
colorExactAlpha(mixed $red, mixed $green, mixed $blue, mixed $alpha)
No description
at line 97
void
colorMatch(Image $image2)
No description
at line 97
int
colorResolve(mixed $red, mixed $green, mixed $blue)
No description
at line 97
int
colorResolveAlpha(mixed $red, mixed $green, mixed $blue, mixed $alpha)
No description
at line 97
void
colorSet(mixed $index, mixed $red, mixed $green, mixed $blue)
No description
at line 97
array
colorsForIndex(mixed $index)
No description
at line 97
int
colorsTotal()
No description
at line 97
int
colorTransparent(mixed $color)
No description
at line 97
void
convolution(array $matrix, float $div, float $offset)
No description
at line 97
void
copy(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $srcW, mixed $srcH)
No description
at line 97
void
copyMerge(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $srcW, mixed $srcH, mixed $opacity)
No description
at line 97
void
copyMergeGray(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $srcW, mixed $srcH, mixed $opacity)
No description
at line 97
void
copyResampled(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $dstW, mixed $dstH, mixed $srcW, mixed $srcH)
No description
at line 97
void
copyResized(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $dstW, mixed $dstH, mixed $srcW, mixed $srcH)
No description
at line 97
Image
cropAuto(int $mode = -1, float $threshold = .5, int $color = -1)
No description
at line 97
void
ellipse(mixed $cx, mixed $cy, mixed $w, mixed $h, mixed $color)
No description
at line 97
void
fill(mixed $x, mixed $y, mixed $color)
No description
at line 97
void
filledArc(mixed $cx, mixed $cy, mixed $w, mixed $h, mixed $s, mixed $e, mixed $color, mixed $style)
No description
at line 97
void
filledEllipse(mixed $cx, mixed $cy, mixed $w, mixed $h, mixed $color)
No description
at line 97
void
filledPolygon(array $points, mixed $numPoints, mixed $color)
No description
at line 97
void
filledRectangle(mixed $x1, mixed $y1, mixed $x2, mixed $y2, mixed $color)
No description
at line 97
void
fillToBorder(mixed $x, mixed $y, mixed $border, mixed $color)
No description
at line 97
void
filter(mixed $filtertype)
No description
at line 97
void
flip(int $mode)
No description
at line 97
array
ftText(mixed $size, mixed $angle, mixed $x, mixed $y, mixed $col, string $fontFile, string $text, array $extrainfo = null)
No description
at line 97
void
gammaCorrect(float $inputgamma, float $outputgamma)
No description
at line 97
array
getClip()
No description
at line 97
int
interlace(mixed $interlace)
No description
at line 97
bool
isTrueColor()
No description
at line 97
void
layerEffect(mixed $effect)
No description
at line 97
void
line(mixed $x1, mixed $y1, mixed $x2, mixed $y2, mixed $color)
No description
at line 97
void
openPolygon(array $points, int $num_points, int $color)
No description
at line 97
void
paletteCopy(Image $source)
No description
at line 97
void
paletteToTrueColor()
No description
at line 97
void
polygon(array $points, mixed $numPoints, mixed $color)
No description
at line 97
array
psText(string $text, mixed $font, mixed $size, mixed $color, mixed $backgroundColor, mixed $x, mixed $y, mixed $space, mixed $tightness, float $angle = null, mixed $antialiasSteps)
No description
at line 97
void
rectangle(mixed $x1, mixed $y1, mixed $x2, mixed $y2, mixed $col)
No description
at line 97
mixed
resolution(int $res_x = null, int $res_y = null)
No description
at line 97
Image
rotate(float $angle, mixed $backgroundColor)
No description
at line 97
void
saveAlpha(bool $saveflag)
No description
at line 97
Image
scale(int $newWidth, int $newHeight = -1, int $mode = IMG_BILINEAR_FIXED)
No description
at line 97
void
setBrush(Image $brush)
No description
at line 97
void
setClip(int $x1, int $y1, int $x2, int $y2)
No description
at line 97
void
setInterpolation(int $method = IMG_BILINEAR_FIXED)
No description
at line 97
void
setPixel(mixed $x, mixed $y, mixed $color)
No description
at line 97
void
setStyle(array $style)
No description
at line 97
void
setThickness(mixed $thickness)
No description
at line 97
void
setTile(Image $tile)
No description
at line 97
void
string(mixed $font, mixed $x, mixed $y, string $s, mixed $col)
No description
at line 97
void
stringUp(mixed $font, mixed $x, mixed $y, string $s, mixed $col)
No description
at line 97
void
trueColorToPalette(bool $dither, mixed $ncolors)
No description
at line 97
array
ttfText(mixed $size, mixed $angle, mixed $x, mixed $y, mixed $color, string $fontfile, string $text)
No description
Traits
Strict class for better experience.