class Image extends Object

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

EMPTY_GIF

deprecated ENLARGE

Properties

int read-only $width
int read-only $height
resource 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 
getFormatFromString($s) deprecated

No description

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($image)

Wraps GD image.

int
getWidth()

Returns image width.

int
getHeight()

Returns image height.

setImageResource($image)

Sets image resource.

resource
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

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

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

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
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

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 123
static array rgb($red, $green, $blue, $transparency = 0)

Returns RGB color.

Parameters

$red
$green
$blue
$transparency

Return Value

array

at line 142
static Image fromFile($file, $format = NULL)

Opens image from file.

Parameters

$file
$format

Return Value

Image

Exceptions

NotSupportedException
UnknownImageFileException

at line 168
static getFormatFromString($s) deprecated

deprecated

No description

Parameters

$s

at line 184
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 207
static Image fromBlank($width, $height, $color = NULL)

Creates blank image.

Parameters

$width
$height
$color

Return Value

Image

at line 235
__construct($image)

Wraps GD image.

Parameters

$image

at line 246
int getWidth()

Returns image width.

Return Value

int

at line 256
int getHeight()

Returns image height.

Return Value

int

at line 267
protected Image setImageResource($image)

Sets image resource.

Parameters

$image

Return Value

Image

at line 281
resource getImageResource()

Returns image GD resource.

Return Value

resource

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

Resizes image.

Parameters

$width
$height
$flags

Return Value

Image

at line 334
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 399
Image crop($left, $top, $width, $height)

Crops image.

Parameters

$left
$top
$width
$height

Return Value

Image

at line 419
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 451
Image sharpen()

Sharpen image.

Return Value

Image

at line 470
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 516
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 559
string toString($type = self::JPEG, $quality = NULL)

Outputs image to string.

Parameters

$type
$quality

Return Value

string

at line 571
string __toString()

Outputs image to string.

Return Value

string

at line 593
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 611
mixed __call($name, $args)

Call to undefined method.

Parameters

$name
$args

Return Value

mixed

Exceptions

MemberAccessException

at line 639
__clone()

No description

at line 84
void alphaBlending(bool $on)

No description

Parameters

bool $on

Return Value

void

at line 84
void antialias(bool $on)

No description

Parameters

bool $on

Return Value

void

at line 84
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 84
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 84
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 84
int colorAllocate(mixed $red, mixed $green, mixed $blue)

No description

Parameters

mixed $red
mixed $green
mixed $blue

Return Value

int

at line 84
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 84
int colorAt(mixed $x, mixed $y)

No description

Parameters

mixed $x
mixed $y

Return Value

int

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

No description

Parameters

mixed $red
mixed $green
mixed $blue

Return Value

int

at line 84
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 84
int colorClosestHWB(mixed $red, mixed $green, mixed $blue)

No description

Parameters

mixed $red
mixed $green
mixed $blue

Return Value

int

at line 84
void colorDeallocate(mixed $color)

No description

Parameters

mixed $color

Return Value

void

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

No description

Parameters

mixed $red
mixed $green
mixed $blue

Return Value

int

at line 84
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 84
void colorMatch(Image $image2)

No description

Parameters

Image $image2

Return Value

void

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

No description

Parameters

mixed $red
mixed $green
mixed $blue

Return Value

int

at line 84
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 84
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 84
array colorsForIndex(mixed $index)

No description

Parameters

mixed $index

Return Value

array

at line 84
int colorsTotal()

No description

Return Value

int

at line 84
int colorTransparent(mixed $color)

No description

Parameters

mixed $color

Return Value

int

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

No description

Parameters

array $matrix
float $div
float $offset

Return Value

void

at line 84
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 84
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 84
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 84
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 84
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 84
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 84
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 84
void fill(mixed $x, mixed $y, mixed $color)

No description

Parameters

mixed $x
mixed $y
mixed $color

Return Value

void

at line 84
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 84
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 84
void filledPolygon(array $points, mixed $numPoints, mixed $color)

No description

Parameters

array $points
mixed $numPoints
mixed $color

Return Value

void

at line 84
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 84
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 84
void filter(mixed $filtertype)

No description

Parameters

mixed $filtertype

Return Value

void

at line 84
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 84
void gammaCorrect(float $inputgamma, float $outputgamma)

No description

Parameters

float $inputgamma
float $outputgamma

Return Value

void

at line 84
int interlace(mixed $interlace)

No description

Parameters

mixed $interlace

Return Value

int

at line 84
bool isTrueColor()

No description

Return Value

bool

at line 84
void layerEffect(mixed $effect)

No description

Parameters

mixed $effect

Return Value

void

at line 84
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 84
void paletteCopy(Image $source)

No description

Parameters

Image $source

Return Value

void

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

No description

Parameters

array $points
mixed $numPoints
mixed $color

Return Value

void

at line 84
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 84
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 84
Image rotate(float $angle, mixed $backgroundColor)

No description

Parameters

float $angle
mixed $backgroundColor

Return Value

Image

at line 84
void saveAlpha(bool $saveflag)

No description

Parameters

bool $saveflag

Return Value

void

at line 84
void setBrush(Image $brush)

No description

Parameters

Image $brush

Return Value

void

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

No description

Parameters

mixed $x
mixed $y
mixed $color

Return Value

void

at line 84
void setStyle(array $style)

No description

Parameters

array $style

Return Value

void

at line 84
void setThickness(mixed $thickness)

No description

Parameters

mixed $thickness

Return Value

void

at line 84
void setTile(Image $tile)

No description

Parameters

Image $tile

Return Value

void

at line 84
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 84
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 84
void trueColorToPalette(bool $dither, mixed $ncolors)

No description

Parameters

bool $dither
mixed $ncolors

Return Value

void

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