Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationLatte
      • ApplicationTracy
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsLatte
      • Framework
      • HttpTracy
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy

Classes

  • ArrayHash
  • ArrayList
  • Arrays
  • Callback
  • DateTime
  • FileSystem
  • Finder
  • Html
  • Image
  • Json
  • LimitedScope
  • MimeTypeDetector
  • ObjectMixin
  • Paginator
  • Random
  • Strings
  • TokenIterator
  • Tokenizer
  • Validators

Interfaces

  • IHtmlString

Exceptions

  • AssertionException
  • JsonException
  • RegexpException
  • TokenizerException
  • UnknownImageFileException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage

Class Image

Basic manipulation with images.

$image = Image::fromFile('nette.jpg');
$image->resize(150, 100);
$image->sharpen();
$image->send();
Nette\Object
Extended by Nette\Utils\Image
Namespace: Nette\Utils
Author: David Grudl
Located at Utils/Image.php
Methods summary
public static array
# rgb( integer $red, integer $green, integer $blue, integer $transparency = 0 )

Returns RGB color.

Returns RGB color.

Parameters

$red
integer
red 0..255
$green
integer
green 0..255
$blue
integer
blue 0..255
$transparency
integer
transparency 0..127

Returns

array
public static Nette\Utils\Image
# fromFile( string $file, mixed & $format = NULL )

Opens image from file.

Opens image from file.

Parameters

$file
string
$format
mixed
detected image format

Returns

Nette\Utils\Image

Throws

Nette\NotSupportedException
if gd extension is not loaded
Nette\Utils\UnknownImageFileException
if file not found or file type is not known
public static mixed
# getFormatFromString( string $s )

Get format from the image stream in the string.

Get format from the image stream in the string.

Parameters

$s
string

Returns

mixed
detected image format
public static Nette\Utils\Image
# fromString( string $s, mixed & $format = NULL )

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

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

Parameters

$s
string
$format
mixed
detected image format

Returns

Nette\Utils\Image

Throws

ImageException
public static Nette\Utils\Image
# fromBlank( integer $width, integer $height, array $color = NULL )

Creates blank image.

Creates blank image.

Parameters

$width
integer
$height
integer
$color
array

Returns

Nette\Utils\Image
public
# __construct( resource $image )

Wraps GD image.

Wraps GD image.

Parameters

$image
resource
public integer
# getWidth( )

Returns image width.

Returns image width.

Returns

integer
public integer
# getHeight( )

Returns image height.

Returns image height.

Returns

integer
protected Nette\Utils\Image
# setImageResource( resource $image )

Sets image resource.

Sets image resource.

Parameters

$image
resource

Returns

Nette\Utils\Image
public resource
# getImageResource( )

Returns image GD resource.

Returns image GD resource.

Returns

resource
public Nette\Utils\Image
# resize( mixed $width, mixed $height, integer $flags = Nette\Utils\Image::FIT )

Resizes image.

Resizes image.

Parameters

$width
mixed
width in pixels or percent
$height
mixed
height in pixels or percent
$flags
integer
flags

Returns

Nette\Utils\Image
public static array
# calculateSize( mixed $srcWidth, mixed $srcHeight, mixed $newWidth, mixed $newHeight, integer $flags = Nette\Utils\Image::FIT )

Calculates dimensions of resized image.

Calculates dimensions of resized image.

Parameters

$srcWidth
mixed
source width
$srcHeight
mixed
source height
$newWidth
mixed
width in pixels or percent
$newHeight
mixed
height in pixels or percent
$flags
integer
flags

Returns

array
public Nette\Utils\Image
# crop( mixed $left, mixed $top, mixed $width, mixed $height )

Crops image.

Crops image.

Parameters

$left
mixed
x-offset in pixels or percent
$top
mixed
y-offset in pixels or percent
$width
mixed
width in pixels or percent
$height
mixed
height in pixels or percent

Returns

Nette\Utils\Image
public static array
# calculateCutout( mixed $srcWidth, mixed $srcHeight, mixed $left, mixed $top, mixed $newWidth, mixed $newHeight )

Calculates dimensions of cutout in image.

Calculates dimensions of cutout in image.

Parameters

$srcWidth
mixed
source width
$srcHeight
mixed
source height
$left
mixed
x-offset in pixels or percent
$top
mixed
y-offset in pixels or percent
$newWidth
mixed
width in pixels or percent
$newHeight
mixed
height in pixels or percent

Returns

array
public Nette\Utils\Image
# sharpen( )

Sharpen image.

Sharpen image.

Returns

Nette\Utils\Image
public Nette\Utils\Image
# place( Nette\Utils\Image $image, mixed $left = 0, mixed $top = 0, integer $opacity = 100 )

Puts another image into this image.

Puts another image into this image.

Parameters

$image
Nette\Utils\Image
$left
mixed
x-coordinate in pixels or percent
$top
mixed
y-coordinate in pixels or percent
$opacity
integer
opacity 0..100

Returns

Nette\Utils\Image
public boolean
# save( string $file = NULL, integer $quality = NULL, integer $type = NULL )

Saves image to the file.

Saves image to the file.

Parameters

$file
string
filename
$quality
integer
quality 0..100 (for JPEG and PNG)
$type
integer
optional image type

Returns

boolean
TRUE on success or FALSE on failure.
public string
# toString( integer $type = Nette\Utils\Image::JPEG, integer $quality = NULL )

Outputs image to string.

Outputs image to string.

Parameters

$type
integer
image type
$quality
integer
quality 0..100 (for JPEG and PNG)

Returns

string
public string
# __toString( )

Outputs image to string.

Outputs image to string.

Returns

string
public boolean
# send( integer $type = Nette\Utils\Image::JPEG, integer $quality = NULL )

Outputs image to browser.

Outputs image to browser.

Parameters

$type
integer
image type
$quality
integer
quality 0..100 (for JPEG and PNG)

Returns

boolean
TRUE on success or FALSE on failure.
public mixed
# __call( string $name, array $args )

Call to undefined method.

Call to undefined method.

Parameters

$name
string
method name
$args
array
arguments

Returns

mixed

Throws

Nette\MemberAccessException

Overrides

Nette\Object::__call()
public
# __clone( )
Methods inherited from Nette\Object
__callStatic(), __get(), __isset(), __set(), __unset(), extensionMethod(), getReflection()
Magic methods summary
public
# alphaBlending( boolean $on )

Parameters

$on
boolean
$on
public
# antialias( boolean $on )

Parameters

$on
boolean
$on
public
# arc( $x, $y, $w, $h, $start, $end, $color )

Parameters

$x

$x
$y

$y
$w

$w
$h

$h
$start

$start
$end

$end
$color

$color
public
# char( integer $font, $x, $y, string $char, $color )

Parameters

$font
integer
$font
$x

$x
$y

$y
$char
string
$char
$color

$color
public
# charUp( integer $font, $x, $y, string $char, $color )

Parameters

$font
integer
$font
$x

$x
$y

$y
$char
string
$char
$color

$color
public integer
# colorAllocate( $red, $green, $blue )

Parameters

$red

$red
$green

$green
$blue

$blue

Returns

integer
public integer
# colorAllocateAlpha( $red, $green, $blue, $alpha )

Parameters

$red

$red
$green

$green
$blue

$blue
$alpha

$alpha

Returns

integer
public integer
# colorAt( $x, $y )

Parameters

$x

$x
$y

$y

Returns

integer
public integer
# colorClosest( $red, $green, $blue )

Parameters

$red

$red
$green

$green
$blue

$blue

Returns

integer
public integer
# colorClosestAlpha( $red, $green, $blue, $alpha )

Parameters

$red

$red
$green

$green
$blue

$blue
$alpha

$alpha

Returns

integer
public integer
# colorClosestHWB( $red, $green, $blue )

Parameters

$red

$red
$green

$green
$blue

$blue

Returns

integer
public
# colorDeallocate( $color )

Parameters

$color

$color
public integer
# colorExact( $red, $green, $blue )

Parameters

$red

$red
$green

$green
$blue

$blue

Returns

integer
public integer
# colorExactAlpha( $red, $green, $blue, $alpha )

Parameters

$red

$red
$green

$green
$blue

$blue
$alpha

$alpha

Returns

integer
public
# colorMatch( Nette\Utils\Image $image2 )

Parameters

$image2
Nette\Utils\Image
$image2
public integer
# colorResolve( $red, $green, $blue )

Parameters

$red

$red
$green

$green
$blue

$blue

Returns

integer
public integer
# colorResolveAlpha( $red, $green, $blue, $alpha )

Parameters

$red

$red
$green

$green
$blue

$blue
$alpha

$alpha

Returns

integer
public
# colorSet( $index, $red, $green, $blue )

Parameters

$index

$index
$red

$red
$green

$green
$blue

$blue
public array
# colorsForIndex( $index )

Parameters

$index

$index

Returns

array
public integer
# colorsTotal( )

Returns

integer
public integer
# colorTransparent( $color = NULL )

Parameters

$color

$color

Returns

integer
public
# convolution( array $matrix, float $div, float $offset )

Parameters

$matrix
array
$matrix
$div
float
$div
$offset
float
$offset
public
# copy( Nette\Utils\Image $src, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH )

Parameters

$src
Nette\Utils\Image
$src
$dstX

$dstX
$dstY

$dstY
$srcX

$srcX
$srcY

$srcY
$srcW

$srcW
$srcH

$srcH
public
# copyMerge( Nette\Utils\Image $src, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH, $opacity )

Parameters

$src
Nette\Utils\Image
$src
$dstX

$dstX
$dstY

$dstY
$srcX

$srcX
$srcY

$srcY
$srcW

$srcW
$srcH

$srcH
$opacity

$opacity
public
# copyMergeGray( Nette\Utils\Image $src, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH, $opacity )

Parameters

$src
Nette\Utils\Image
$src
$dstX

$dstX
$dstY

$dstY
$srcX

$srcX
$srcY

$srcY
$srcW

$srcW
$srcH

$srcH
$opacity

$opacity
public
# copyResampled( Nette\Utils\Image $src, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH )

Parameters

$src
Nette\Utils\Image
$src
$dstX

$dstX
$dstY

$dstY
$srcX

$srcX
$srcY

$srcY
$dstW

$dstW
$dstH

$dstH
$srcW

$srcW
$srcH

$srcH
public
# copyResized( Nette\Utils\Image $src, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH )

Parameters

$src
Nette\Utils\Image
$src
$dstX

$dstX
$dstY

$dstY
$srcX

$srcX
$srcY

$srcY
$dstW

$dstW
$dstH

$dstH
$srcW

$srcW
$srcH

$srcH
public
# dashedLine( $x1, $y1, $x2, $y2, $color )

Parameters

$x1

$x1
$y1

$y1
$x2

$x2
$y2

$y2
$color

$color
public
# ellipse( $cx, $cy, $w, $h, $color )

Parameters

$cx

$cx
$cy

$cy
$w

$w
$h

$h
$color

$color
public
# fill( $x, $y, $color )

Parameters

$x

$x
$y

$y
$color

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

Parameters

$cx

$cx
$cy

$cy
$w

$w
$h

$h
$s

$s
$e

$e
$color

$color
$style

$style
public
# filledEllipse( $cx, $cy, $w, $h, $color )

Parameters

$cx

$cx
$cy

$cy
$w

$w
$h

$h
$color

$color
public
# filledPolygon( array $points, $numPoints, $color )

Parameters

$points
array
$points
$numPoints

$numPoints
$color

$color
public
# filledRectangle( $x1, $y1, $x2, $y2, $color )

Parameters

$x1

$x1
$y1

$y1
$x2

$x2
$y2

$y2
$color

$color
public
# fillToBorder( $x, $y, $border, $color )

Parameters

$x

$x
$y

$y
$border

$border
$color

$color
public
# filter( $filtertype )

Parameters

$filtertype

$filtertype
public array
# ftText( $size, $angle, $x, $y, $col, string $fontFile, string $text, array $extrainfo = NULL )

Parameters

$size

$size
$angle

$angle
$x

$x
$y

$y
$col

$col
$fontFile
string
$fontFile
$text
string
$text
$extrainfo
array
$extrainfo

Returns

array
public
# gammaCorrect( float $inputgamma, float $outputgamma )

Parameters

$inputgamma
float
$inputgamma
$outputgamma
float
$outputgamma
public integer
# interlace( $interlace = NULL )

Parameters

$interlace

$interlace

Returns

integer
public boolean
# isTrueColor( )

Returns

boolean
public
# layerEffect( $effect )

Parameters

$effect

$effect
public
# line( $x1, $y1, $x2, $y2, $color )

Parameters

$x1

$x1
$y1

$y1
$x2

$x2
$y2

$y2
$color

$color
public
# paletteCopy( Nette\Utils\Image $source )

Parameters

$source
Nette\Utils\Image
$source
public
# polygon( array $points, $numPoints, $color )

Parameters

$points
array
$points
$numPoints

$numPoints
$color

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

Parameters

$text
string
$text
$font

$font
$size

$size
$color

$color
$backgroundColor

$backgroundColor
$x

$x
$y

$y
$space

$space
$tightness

$tightness
$angle
float
$angle
$antialiasSteps

$antialiasSteps

Returns

array
public
# rectangle( $x1, $y1, $x2, $y2, $col )

Parameters

$x1

$x1
$y1

$y1
$x2

$x2
$y2

$y2
$col

$col
public Nette\Utils\Image
# rotate( float $angle, $backgroundColor )

Parameters

$angle
float
$angle
$backgroundColor

$backgroundColor

Returns

Nette\Utils\Image
public
# saveAlpha( boolean $saveflag )

Parameters

$saveflag
boolean
$saveflag
public
# setBrush( Nette\Utils\Image $brush )

Parameters

$brush
Nette\Utils\Image
$brush
public
# setPixel( $x, $y, $color )

Parameters

$x

$x
$y

$y
$color

$color
public
# setStyle( array $style )

Parameters

$style
array
$style
public
# setThickness( $thickness )

Parameters

$thickness

$thickness
public
# setTile( Nette\Utils\Image $tile )

Parameters

$tile
Nette\Utils\Image
$tile
public
# string( $font, $x, $y, string $s, $col )

Parameters

$font

$font
$x

$x
$y

$y
$s
string
$s
$col

$col
public
# stringUp( $font, $x, $y, string $s, $col )

Parameters

$font

$font
$x

$x
$y

$y
$s
string
$s
$col

$col
public
# trueColorToPalette( boolean $dither, $ncolors )

Parameters

$dither
boolean
$dither
$ncolors

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

Parameters

$size

$size
$angle

$angle
$x

$x
$y

$y
$color

$color
$fontfile
string
$fontfile
$text
string
$text

Returns

array
Constants summary
integer SHRINK_ONLY 1
#

Nette\Utils\Image::resize() only shrinks images

Nette\Utils\Image::resize() only shrinks images

integer STRETCH 2
#

Nette\Utils\Image::resize() will ignore aspect ratio

Nette\Utils\Image::resize() will ignore aspect ratio

integer FIT 0
#

Nette\Utils\Image::resize() fits in given area so its dimensions are less than or equal to the required dimensions

Nette\Utils\Image::resize() fits in given area so its dimensions are less than or equal to the required dimensions

integer FILL 4
#

Nette\Utils\Image::resize() fills given area so its dimensions are greater than or equal to the required dimensions

Nette\Utils\Image::resize() fills given area so its dimensions are greater than or equal to the required dimensions

integer EXACT 8
#

Nette\Utils\Image::resize() fills given area exactly

Nette\Utils\Image::resize() fills given area exactly

integer JPEG IMAGETYPE_JPEG
#

Int

image types Nette\Utils\Image::send()
integer PNG IMAGETYPE_PNG
#

Int

image types Nette\Utils\Image::send()
integer GIF IMAGETYPE_GIF
#

Int

image types Nette\Utils\Image::send()
string EMPTY_GIF "GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00!\xf9\x04\x01\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;"
#
integer ENLARGE 0
#

Deprecated

Magic properties summary
public read-only integer $width
#
public read-only integer $height
#
public read-only resource $imageResource
#
Magic properties inherited from Nette\Object
$reflection
Nette 2.2 API documentation generated by ApiGen 2.8.0