class Image

Basic manipulation with images.

$image = Image::fromFile('nette.jpg'); $image->resize(150, 100); $image->sharpen(); $image->send();

Traits

Strict class for better experience.

Constants

SHRINK_ONLY

{@link resize()} only shrinks images

STRETCH

{@link resize()} will ignore aspect ratio

FIT

{@link resize()} fits in given area so its dimensions are less than or equal to the required dimensions

FILL

{@link resize()} fills given area so its dimensions are greater than or equal to the required dimensions

EXACT

{@link resize()} fills given area exactly

JPEG

image types

PNG

image types

GIF

image types

WEBP

image types

EMPTY_GIF

FORMATS

Methods

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

Returns RGB color (0.

static Image
fromFile(string $file, int $detectedFormat = null)

Opens image from file.

static Image
fromString(string $s, int $detectedFormat = null)

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

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

Creates blank image.

__construct(resource $image)

Wraps GD image.

int
getWidth()

Returns image width.

int
getHeight()

Returns image height.

setImageResource(resource $image)

Sets image resource.

resource
getImageResource()

Returns image GD resource.

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

Resizes image.

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

Calculates dimensions of resized image.

crop(int|string $left, int|string $top, int|string $width, int|string $height)

Crops image.

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

Calculates dimensions of cutout in image.

sharpen()

Sharpen image.

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

Puts another image into this image.

void
save(string $file, int $quality = null, int $type = null)

Saves image to the file. Quality is 0.

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

Outputs image to string. Quality is 0.

string
__toString()

Outputs image to string.

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

Outputs image to browser. Quality is 0.

mixed
__call(string $name, array $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($x, $y, $w, $h, $start, $end, $color)

No description

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

No description

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

No description

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

No description

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

No description

int
colorAt($x, $y)

No description

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

No description

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

No description

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

No description

void
colorDeallocate($color)

No description

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

No description

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

No description

void
colorMatch(Image $image2)

No description

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

No description

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

No description

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

No description

array
colorsForIndex($index)

No description

int
colorsTotal()

No description

int
colorTransparent($color = null)

No description

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

No description

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

No description

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

No description

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

No description

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

No description

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

No description

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

No description

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

No description

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

No description

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

No description

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

No description

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

No description

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

No description

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

No description

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

No description

void
filter($filtertype)

No description

void
flip(int $mode)

No description

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

No description

void
gammaCorrect(float $inputgamma, float $outputgamma)

No description

int
interlace($interlace = null)

No description

bool
isTrueColor()

No description

void
layerEffect($effect)

No description

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

No description

void
paletteCopy(Image $source)

No description

void
paletteToTrueColor()

No description

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

No description

array
psText(string $text, $font, $size, $color, $backgroundColor, $x, $y, $space = null, $tightness = null, float $angle = null, $antialiasSteps = null)

No description

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

No description

Image
rotate(float $angle, $backgroundColor)

No description

void
saveAlpha(bool $saveflag)

No description

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

No description

void
setBrush(Image $brush)

No description

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

No description

void
setStyle(array $style)

No description

void
setThickness($thickness)

No description

void
setTile(Image $tile)

No description

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

No description

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

No description

void
trueColorToPalette(bool $dither, $ncolors)

No description

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

No description

Details

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

Returns RGB color (0.

.255) and transparency (0..127).

Parameters

int $red
int $green
int $blue
int $transparency

Return Value

array

at line 144
static Image fromFile(string $file, int $detectedFormat = null)

Opens image from file.

Parameters

string $file
int $detectedFormat

Return Value

Image

Exceptions

NotSupportedException if gd extension is not loaded
UnknownImageFileException if file not found or file type is not known

at line 166
static Image fromString(string $s, int $detectedFormat = null)

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

Parameters

string $s
int $detectedFormat

Return Value

Image

Exceptions

ImageException

at line 187
static Image fromBlank(int $width, int $height, array $color = null)

Creates blank image.

Parameters

int $width
int $height
array $color

Return Value

Image

at line 213
__construct(resource $image)

Wraps GD image.

Parameters

resource $image

at line 223
int getWidth()

Returns image width.

Return Value

int

at line 232
int getHeight()

Returns image height.

Return Value

int

at line 243
protected Image setImageResource(resource $image)

Sets image resource.

Parameters

resource $image

Return Value

Image

at line 257
resource getImageResource()

Returns image GD resource.

Return Value

resource

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

Resizes image.

Parameters

$width
$height
int $flags

Return Value

Image

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

Calculates dimensions of resized image.

Parameters

int $srcWidth
int $srcHeight
$newWidth
$newHeight
int $flags

Return Value

array

at line 364
Image crop(int|string $left, int|string $top, int|string $width, int|string $height)

Crops image.

Parameters

int|string $left in pixels or percent
int|string $top in pixels or percent
int|string $width in pixels or percent
int|string $height in pixels or percent

Return Value

Image

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

Calculates dimensions of cutout in image.

Parameters

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

Return Value

array

at line 412
Image sharpen()

Sharpen image.

Return Value

Image

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

Puts another image into this image.

Parameters

Image $image
$left
$top
int $opacity

Return Value

Image

at line 484
void save(string $file, int $quality = null, int $type = null)

Saves image to the file. Quality is 0.

.100 for JPEG and WEBP, 0..9 for PNG.

Parameters

string $file
int $quality
int $type

Return Value

void

Exceptions

ImageException

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

Outputs image to string. Quality is 0.

.100 for JPEG and WEBP, 0..9 for PNG.

Parameters

int $type
int $quality

Return Value

string

at line 513
string __toString()

Outputs image to string.

Return Value

string

at line 530
void send(int $type = self::JPEG, int $quality = null)

Outputs image to browser. Quality is 0.

.100 for JPEG and WEBP, 0..9 for PNG.

Parameters

int $type
int $quality

Return Value

void

Exceptions

ImageException

at line 580
mixed __call(string $name, array $args)

Call to undefined method.

Parameters

string $name
array $args

Return Value

mixed

Exceptions

MemberAccessException

at line 606
__clone()

at line 617
__sleep()

Prevents serialization.

at line 90
void alphaBlending(bool $on)

Parameters

bool $on

Return Value

void

at line 90
void antialias(bool $on)

Parameters

bool $on

Return Value

void

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

Parameters

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

Return Value

void

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

Parameters

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

Return Value

void

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

Parameters

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

Return Value

void

at line 90
int colorAllocate($red, $green, $blue)

Parameters

$red
$green
$blue

Return Value

int

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

Parameters

$red
$green
$blue
$alpha

Return Value

int

at line 90
int colorAt($x, $y)

Parameters

$x
$y

Return Value

int

at line 90
int colorClosest($red, $green, $blue)

Parameters

$red
$green
$blue

Return Value

int

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

Parameters

$red
$green
$blue
$alpha

Return Value

int

at line 90
int colorClosestHWB($red, $green, $blue)

Parameters

$red
$green
$blue

Return Value

int

at line 90
void colorDeallocate($color)

Parameters

$color

Return Value

void

at line 90
int colorExact($red, $green, $blue)

Parameters

$red
$green
$blue

Return Value

int

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

Parameters

$red
$green
$blue
$alpha

Return Value

int

at line 90
void colorMatch(Image $image2)

Parameters

Image $image2

Return Value

void

at line 90
int colorResolve($red, $green, $blue)

Parameters

$red
$green
$blue

Return Value

int

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

Parameters

$red
$green
$blue
$alpha

Return Value

int

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

Parameters

$index
$red
$green
$blue

Return Value

void

at line 90
array colorsForIndex($index)

Parameters

$index

Return Value

array

at line 90
int colorsTotal()

Return Value

int

at line 90
int colorTransparent($color = null)

Parameters

$color

Return Value

int

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

Parameters

array $matrix
float $div
float $offset

Return Value

void

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

Parameters

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

Return Value

void

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

Parameters

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

Return Value

void

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

Parameters

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

Return Value

void

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

Parameters

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

Return Value

void

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

Parameters

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

Return Value

void

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

Parameters

int $mode
float $threshold
int $color

Return Value

Image

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

Parameters

$x1
$y1
$x2
$y2
$color

Return Value

void

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

Parameters

$cx
$cy
$w
$h
$color

Return Value

void

at line 90
void fill($x, $y, $color)

Parameters

$x
$y
$color

Return Value

void

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

Parameters

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

Return Value

void

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

Parameters

$cx
$cy
$w
$h
$color

Return Value

void

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

Parameters

array $points
$numPoints
$color

Return Value

void

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

Parameters

$x1
$y1
$x2
$y2
$color

Return Value

void

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

Parameters

$x
$y
$border
$color

Return Value

void

at line 90
void filter($filtertype)

Parameters

$filtertype

Return Value

void

at line 90
void flip(int $mode)

Parameters

int $mode

Return Value

void

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

Parameters

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

Return Value

array

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

Parameters

float $inputgamma
float $outputgamma

Return Value

void

at line 90
int interlace($interlace = null)

Parameters

$interlace

Return Value

int

at line 90
bool isTrueColor()

Return Value

bool

at line 90
void layerEffect($effect)

Parameters

$effect

Return Value

void

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

Parameters

$x1
$y1
$x2
$y2
$color

Return Value

void

at line 90
void paletteCopy(Image $source)

Parameters

Image $source

Return Value

void

at line 90
void paletteToTrueColor()

Return Value

void

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

Parameters

array $points
$numPoints
$color

Return Value

void

at line 90
array psText(string $text, $font, $size, $color, $backgroundColor, $x, $y, $space = null, $tightness = null, float $angle = null, $antialiasSteps = null)

Parameters

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

Return Value

array

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

Parameters

$x1
$y1
$x2
$y2
$col

Return Value

void

at line 90
Image rotate(float $angle, $backgroundColor)

Parameters

float $angle
$backgroundColor

Return Value

Image

at line 90
void saveAlpha(bool $saveflag)

Parameters

bool $saveflag

Return Value

void

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

Parameters

int $newWidth
int $newHeight
int $mode

Return Value

Image

at line 90
void setBrush(Image $brush)

Parameters

Image $brush

Return Value

void

at line 90
void setPixel($x, $y, $color)

Parameters

$x
$y
$color

Return Value

void

at line 90
void setStyle(array $style)

Parameters

array $style

Return Value

void

at line 90
void setThickness($thickness)

Parameters

$thickness

Return Value

void

at line 90
void setTile(Image $tile)

Parameters

Image $tile

Return Value

void

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

Parameters

$font
$x
$y
string $s
$col

Return Value

void

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

Parameters

$font
$x
$y
string $s
$col

Return Value

void

at line 90
void trueColorToPalette(bool $dither, $ncolors)

Parameters

bool $dither
$ncolors

Return Value

void

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

Parameters

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

Return Value

array