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

EMPTY_GIF

Properties

int read-only $width
int read-only $height
resource|GdImage read-only $imageResource

Methods

static array
rgb($red, $green, $blue, $transparency = 0)

Returns RGB color.

static Image
fromFile($file, $format = null)

Opens image from file.

static Image
fromString($s, $format = null)

Create a new image from the image stream in the string.

static Image
fromBlank($width, $height, $color = null)

Creates blank image.

__construct(resource|GdImage $image)

Wraps GD image.

int
getWidth()

Returns image width.

int
getHeight()

Returns image height.

setImageResource(resource|GdImage $image)

Sets image resource.

resource|GdImage
getImageResource()

Returns image GD resource.

resize($width, $height, $flags = self::FIT)

Resizes image.

static array
calculateSize($srcWidth, $srcHeight, $newWidth, $newHeight, $flags = self::FIT)

Calculates dimensions of resized image.

crop($left, $top, $width, $height)

Crops image.

static array
calculateCutout($srcWidth, $srcHeight, $left, $top, $newWidth, $newHeight)

Calculates dimensions of cutout in image.

sharpen()

Sharpen image.

place(Image $image, $left = 0, $top = 0, $opacity = 100)

Puts another image into this image.

bool
save($file = null, $quality = null, $type = null)

Saves image to the file.

string
toString($type = self::JPEG, $quality = null)

Outputs image to string.

string
__toString()

Outputs image to string.

bool
send($type = self::JPEG, $quality = null)

Outputs image to browser.

mixed
__call($name, $args)

Call to undefined method.

__clone()

No description

__sleep()

Prevents serialization.

void
alphaBlending(bool $on)

No description

void
antialias(bool $on)

No description

void
arc(mixed $x, mixed $y, mixed $w, mixed $h, mixed $start, mixed $end, mixed $color)

No description

void
char(int $font, mixed $x, mixed $y, string $char, mixed $color)

No description

void
charUp(int $font, mixed $x, mixed $y, string $char, mixed $color)

No description

int
colorAllocate(mixed $red, mixed $green, mixed $blue)

No description

int
colorAllocateAlpha(mixed $red, mixed $green, mixed $blue, mixed $alpha)

No description

int
colorAt(mixed $x, mixed $y)

No description

int
colorClosest(mixed $red, mixed $green, mixed $blue)

No description

int
colorClosestAlpha(mixed $red, mixed $green, mixed $blue, mixed $alpha)

No description

int
colorClosestHWB(mixed $red, mixed $green, mixed $blue)

No description

void
colorDeallocate(mixed $color)

No description

int
colorExact(mixed $red, mixed $green, mixed $blue)

No description

int
colorExactAlpha(mixed $red, mixed $green, mixed $blue, mixed $alpha)

No description

void
colorMatch(Image $image2)

No description

int
colorResolve(mixed $red, mixed $green, mixed $blue)

No description

int
colorResolveAlpha(mixed $red, mixed $green, mixed $blue, mixed $alpha)

No description

void
colorSet(mixed $index, mixed $red, mixed $green, mixed $blue)

No description

array
colorsForIndex(mixed $index)

No description

int
colorsTotal()

No description

int
colorTransparent(mixed $color)

No description

void
convolution(array $matrix, float $div, float $offset)

No description

void
copy(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $srcW, mixed $srcH)

No description

void
copyMerge(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $srcW, mixed $srcH, mixed $opacity)

No description

void
copyMergeGray(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $srcW, mixed $srcH, mixed $opacity)

No description

void
copyResampled(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $dstW, mixed $dstH, mixed $srcW, mixed $srcH)

No description

void
copyResized(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $dstW, mixed $dstH, mixed $srcW, mixed $srcH)

No description

cropAuto(int $mode = -1, float $threshold = .5, int $color = -1)

No description

void
dashedLine(mixed $x1, mixed $y1, mixed $x2, mixed $y2, mixed $color)

No description

void
ellipse(mixed $cx, mixed $cy, mixed $w, mixed $h, mixed $color)

No description

void
fill(mixed $x, mixed $y, mixed $color)

No description

void
filledArc(mixed $cx, mixed $cy, mixed $w, mixed $h, mixed $s, mixed $e, mixed $color, mixed $style)

No description

void
filledEllipse(mixed $cx, mixed $cy, mixed $w, mixed $h, mixed $color)

No description

void
filledPolygon(array $points, mixed $numPoints, mixed $color)

No description

void
filledRectangle(mixed $x1, mixed $y1, mixed $x2, mixed $y2, mixed $color)

No description

void
fillToBorder(mixed $x, mixed $y, mixed $border, mixed $color)

No description

void
filter(mixed $filtertype)

No description

void
flip(int $mode)

No description

array
ftText(mixed $size, mixed $angle, mixed $x, mixed $y, mixed $col, string $fontFile, string $text, array $extrainfo = null)

No description

void
gammaCorrect(float $inputgamma, float $outputgamma)

No description

int
interlace(mixed $interlace)

No description

bool
isTrueColor()

No description

void
layerEffect(mixed $effect)

No description

void
line(mixed $x1, mixed $y1, mixed $x2, mixed $y2, mixed $color)

No description

void
paletteCopy(Image $source)

No description

void
paletteToTrueColor()

No description

void
polygon(array $points, mixed $numPoints, mixed $color)

No description

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

void
rectangle(mixed $x1, mixed $y1, mixed $x2, mixed $y2, mixed $col)

No description

rotate(float $angle, mixed $backgroundColor)

No description

void
saveAlpha(bool $saveflag)

No description

scale(int $newWidth, int $newHeight = -1, int $mode = IMG_BILINEAR_FIXED)

No description

void
setBrush(Image $brush)

No description

void
setPixel(mixed $x, mixed $y, mixed $color)

No description

void
setStyle(array $style)

No description

void
setThickness(mixed $thickness)

No description

void
setTile(Image $tile)

No description

void
string(mixed $font, mixed $x, mixed $y, string $s, mixed $col)

No description

void
stringUp(mixed $font, mixed $x, mixed $y, string $s, mixed $col)

No description

void
trueColorToPalette(bool $dither, mixed $ncolors)

No description

array
ttfText(mixed $size, mixed $angle, mixed $x, mixed $y, mixed $color, string $fontfile, string $text)

No description

Details

at line 130
static array rgb($red, $green, $blue, $transparency = 0)

Returns RGB color.

Parameters

$red
$green
$blue
$transparency

Return Value

array

at line 149
static Image fromFile($file, $format = null)

Opens image from file.

Parameters

$file
$format

Return Value

Image

Exceptions

NotSupportedException
UnknownImageFileException

at line 176
static Image fromString($s, $format = null)

Create a new image from the image stream in the string.

Parameters

$s
$format

Return Value

Image

Exceptions

ImageException

at line 201
static Image fromBlank($width, $height, $color = null)

Creates blank image.

Parameters

$width
$height
$color

Return Value

Image

at line 229
__construct(resource|GdImage $image)

Wraps GD image.

Parameters

resource|GdImage $image

at line 240
int getWidth()

Returns image width.

Return Value

int

at line 250
int getHeight()

Returns image height.

Return Value

int

at line 261
protected Image setImageResource(resource|GdImage $image)

Sets image resource.

Parameters

resource|GdImage $image

Return Value

Image

at line 275
resource|GdImage getImageResource()

Returns image GD resource.

Return Value

resource|GdImage

at line 288
Image resize($width, $height, $flags = self::FIT)

Resizes image.

Parameters

$width
$height
$flags

Return Value

Image

at line 322
static array calculateSize($srcWidth, $srcHeight, $newWidth, $newHeight, $flags = self::FIT)

Calculates dimensions of resized image.

Parameters

$srcWidth
$srcHeight
$newWidth
$newHeight
$flags

Return Value

array

at line 389
Image crop($left, $top, $width, $height)

Crops image.

Parameters

$left
$top
$width
$height

Return Value

Image

at line 414
static array calculateCutout($srcWidth, $srcHeight, $left, $top, $newWidth, $newHeight)

Calculates dimensions of cutout in image.

Parameters

$srcWidth
$srcHeight
$left
$top
$newWidth
$newHeight

Return Value

array

at line 446
Image sharpen()

Sharpen image.

Return Value

Image

at line 465
Image place(Image $image, $left = 0, $top = 0, $opacity = 100)

Puts another image into this image.

Parameters

Image $image
$left
$top
$opacity

Return Value

Image

at line 522
bool save($file = null, $quality = null, $type = null)

Saves image to the file.

Parameters

$file
$quality
$type

Return Value

bool

true on success or false on failure.

at line 564
string toString($type = self::JPEG, $quality = null)

Outputs image to string.

Parameters

$type
$quality

Return Value

string

at line 576
string __toString()

Outputs image to string.

Return Value

string

at line 598
bool send($type = self::JPEG, $quality = null)

Outputs image to browser.

Parameters

$type
$quality

Return Value

bool

true on success or false on failure.

at line 616
mixed __call($name, $args)

Call to undefined method.

Parameters

$name
$args

Return Value

mixed

Exceptions

MemberAccessException

at line 642
__clone()

No description

at line 669
__sleep()

Prevents serialization.

at line 88
void alphaBlending(bool $on)

No description

Parameters

bool $on

Return Value

void

at line 88
void antialias(bool $on)

No description

Parameters

bool $on

Return Value

void

at line 88
void arc(mixed $x, mixed $y, mixed $w, mixed $h, mixed $start, mixed $end, mixed $color)

No description

Parameters

mixed $x
mixed $y
mixed $w
mixed $h
mixed $start
mixed $end
mixed $color

Return Value

void

at line 88
void char(int $font, mixed $x, mixed $y, string $char, mixed $color)

No description

Parameters

int $font
mixed $x
mixed $y
string $char
mixed $color

Return Value

void

at line 88
void charUp(int $font, mixed $x, mixed $y, string $char, mixed $color)

No description

Parameters

int $font
mixed $x
mixed $y
string $char
mixed $color

Return Value

void

at line 88
int colorAllocate(mixed $red, mixed $green, mixed $blue)

No description

Parameters

mixed $red
mixed $green
mixed $blue

Return Value

int

at line 88
int colorAllocateAlpha(mixed $red, mixed $green, mixed $blue, mixed $alpha)

No description

Parameters

mixed $red
mixed $green
mixed $blue
mixed $alpha

Return Value

int

at line 88
int colorAt(mixed $x, mixed $y)

No description

Parameters

mixed $x
mixed $y

Return Value

int

at line 88
int colorClosest(mixed $red, mixed $green, mixed $blue)

No description

Parameters

mixed $red
mixed $green
mixed $blue

Return Value

int

at line 88
int colorClosestAlpha(mixed $red, mixed $green, mixed $blue, mixed $alpha)

No description

Parameters

mixed $red
mixed $green
mixed $blue
mixed $alpha

Return Value

int

at line 88
int colorClosestHWB(mixed $red, mixed $green, mixed $blue)

No description

Parameters

mixed $red
mixed $green
mixed $blue

Return Value

int

at line 88
void colorDeallocate(mixed $color)

No description

Parameters

mixed $color

Return Value

void

at line 88
int colorExact(mixed $red, mixed $green, mixed $blue)

No description

Parameters

mixed $red
mixed $green
mixed $blue

Return Value

int

at line 88
int colorExactAlpha(mixed $red, mixed $green, mixed $blue, mixed $alpha)

No description

Parameters

mixed $red
mixed $green
mixed $blue
mixed $alpha

Return Value

int

at line 88
void colorMatch(Image $image2)

No description

Parameters

Image $image2

Return Value

void

at line 88
int colorResolve(mixed $red, mixed $green, mixed $blue)

No description

Parameters

mixed $red
mixed $green
mixed $blue

Return Value

int

at line 88
int colorResolveAlpha(mixed $red, mixed $green, mixed $blue, mixed $alpha)

No description

Parameters

mixed $red
mixed $green
mixed $blue
mixed $alpha

Return Value

int

at line 88
void colorSet(mixed $index, mixed $red, mixed $green, mixed $blue)

No description

Parameters

mixed $index
mixed $red
mixed $green
mixed $blue

Return Value

void

at line 88
array colorsForIndex(mixed $index)

No description

Parameters

mixed $index

Return Value

array

at line 88
int colorsTotal()

No description

Return Value

int

at line 88
int colorTransparent(mixed $color)

No description

Parameters

mixed $color

Return Value

int

at line 88
void convolution(array $matrix, float $div, float $offset)

No description

Parameters

array $matrix
float $div
float $offset

Return Value

void

at line 88
void copy(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $srcW, mixed $srcH)

No description

Parameters

Image $src
mixed $dstX
mixed $dstY
mixed $srcX
mixed $srcY
mixed $srcW
mixed $srcH

Return Value

void

at line 88
void copyMerge(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $srcW, mixed $srcH, mixed $opacity)

No description

Parameters

Image $src
mixed $dstX
mixed $dstY
mixed $srcX
mixed $srcY
mixed $srcW
mixed $srcH
mixed $opacity

Return Value

void

at line 88
void copyMergeGray(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $srcW, mixed $srcH, mixed $opacity)

No description

Parameters

Image $src
mixed $dstX
mixed $dstY
mixed $srcX
mixed $srcY
mixed $srcW
mixed $srcH
mixed $opacity

Return Value

void

at line 88
void copyResampled(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $dstW, mixed $dstH, mixed $srcW, mixed $srcH)

No description

Parameters

Image $src
mixed $dstX
mixed $dstY
mixed $srcX
mixed $srcY
mixed $dstW
mixed $dstH
mixed $srcW
mixed $srcH

Return Value

void

at line 88
void copyResized(Image $src, mixed $dstX, mixed $dstY, mixed $srcX, mixed $srcY, mixed $dstW, mixed $dstH, mixed $srcW, mixed $srcH)

No description

Parameters

Image $src
mixed $dstX
mixed $dstY
mixed $srcX
mixed $srcY
mixed $dstW
mixed $dstH
mixed $srcW
mixed $srcH

Return Value

void

at line 88
Image cropAuto(int $mode = -1, float $threshold = .5, int $color = -1)

No description

Parameters

int $mode
float $threshold
int $color

Return Value

Image

at line 88
void dashedLine(mixed $x1, mixed $y1, mixed $x2, mixed $y2, mixed $color)

No description

Parameters

mixed $x1
mixed $y1
mixed $x2
mixed $y2
mixed $color

Return Value

void

at line 88
void ellipse(mixed $cx, mixed $cy, mixed $w, mixed $h, mixed $color)

No description

Parameters

mixed $cx
mixed $cy
mixed $w
mixed $h
mixed $color

Return Value

void

at line 88
void fill(mixed $x, mixed $y, mixed $color)

No description

Parameters

mixed $x
mixed $y
mixed $color

Return Value

void

at line 88
void filledArc(mixed $cx, mixed $cy, mixed $w, mixed $h, mixed $s, mixed $e, mixed $color, mixed $style)

No description

Parameters

mixed $cx
mixed $cy
mixed $w
mixed $h
mixed $s
mixed $e
mixed $color
mixed $style

Return Value

void

at line 88
void filledEllipse(mixed $cx, mixed $cy, mixed $w, mixed $h, mixed $color)

No description

Parameters

mixed $cx
mixed $cy
mixed $w
mixed $h
mixed $color

Return Value

void

at line 88
void filledPolygon(array $points, mixed $numPoints, mixed $color)

No description

Parameters

array $points
mixed $numPoints
mixed $color

Return Value

void

at line 88
void filledRectangle(mixed $x1, mixed $y1, mixed $x2, mixed $y2, mixed $color)

No description

Parameters

mixed $x1
mixed $y1
mixed $x2
mixed $y2
mixed $color

Return Value

void

at line 88
void fillToBorder(mixed $x, mixed $y, mixed $border, mixed $color)

No description

Parameters

mixed $x
mixed $y
mixed $border
mixed $color

Return Value

void

at line 88
void filter(mixed $filtertype)

No description

Parameters

mixed $filtertype

Return Value

void

at line 88
void flip(int $mode)

No description

Parameters

int $mode

Return Value

void

at line 88
array ftText(mixed $size, mixed $angle, mixed $x, mixed $y, mixed $col, string $fontFile, string $text, array $extrainfo = null)

No description

Parameters

mixed $size
mixed $angle
mixed $x
mixed $y
mixed $col
string $fontFile
string $text
array $extrainfo

Return Value

array

at line 88
void gammaCorrect(float $inputgamma, float $outputgamma)

No description

Parameters

float $inputgamma
float $outputgamma

Return Value

void

at line 88
int interlace(mixed $interlace)

No description

Parameters

mixed $interlace

Return Value

int

at line 88
bool isTrueColor()

No description

Return Value

bool

at line 88
void layerEffect(mixed $effect)

No description

Parameters

mixed $effect

Return Value

void

at line 88
void line(mixed $x1, mixed $y1, mixed $x2, mixed $y2, mixed $color)

No description

Parameters

mixed $x1
mixed $y1
mixed $x2
mixed $y2
mixed $color

Return Value

void

at line 88
void paletteCopy(Image $source)

No description

Parameters

Image $source

Return Value

void

at line 88
void paletteToTrueColor()

No description

Return Value

void

at line 88
void polygon(array $points, mixed $numPoints, mixed $color)

No description

Parameters

array $points
mixed $numPoints
mixed $color

Return Value

void

at line 88
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

Parameters

string $text
mixed $font
mixed $size
mixed $color
mixed $backgroundColor
mixed $x
mixed $y
mixed $space
mixed $tightness
float $angle
mixed $antialiasSteps

Return Value

array

at line 88
void rectangle(mixed $x1, mixed $y1, mixed $x2, mixed $y2, mixed $col)

No description

Parameters

mixed $x1
mixed $y1
mixed $x2
mixed $y2
mixed $col

Return Value

void

at line 88
Image rotate(float $angle, mixed $backgroundColor)

No description

Parameters

float $angle
mixed $backgroundColor

Return Value

Image

at line 88
void saveAlpha(bool $saveflag)

No description

Parameters

bool $saveflag

Return Value

void

at line 88
Image scale(int $newWidth, int $newHeight = -1, int $mode = IMG_BILINEAR_FIXED)

No description

Parameters

int $newWidth
int $newHeight
int $mode

Return Value

Image

at line 88
void setBrush(Image $brush)

No description

Parameters

Image $brush

Return Value

void

at line 88
void setPixel(mixed $x, mixed $y, mixed $color)

No description

Parameters

mixed $x
mixed $y
mixed $color

Return Value

void

at line 88
void setStyle(array $style)

No description

Parameters

array $style

Return Value

void

at line 88
void setThickness(mixed $thickness)

No description

Parameters

mixed $thickness

Return Value

void

at line 88
void setTile(Image $tile)

No description

Parameters

Image $tile

Return Value

void

at line 88
void string(mixed $font, mixed $x, mixed $y, string $s, mixed $col)

No description

Parameters

mixed $font
mixed $x
mixed $y
string $s
mixed $col

Return Value

void

at line 88
void stringUp(mixed $font, mixed $x, mixed $y, string $s, mixed $col)

No description

Parameters

mixed $font
mixed $x
mixed $y
string $s
mixed $col

Return Value

void

at line 88
void trueColorToPalette(bool $dither, mixed $ncolors)

No description

Parameters

bool $dither
mixed $ncolors

Return Value

void

at line 88
array ttfText(mixed $size, mixed $angle, mixed $x, mixed $y, mixed $color, string $fontfile, string $text)

No description

Parameters

mixed $size
mixed $angle
mixed $x
mixed $y
mixed $color
string $fontfile
string $text

Return Value

array

Traits

Strict class for better experience.