public
|
#
__construct( resource $handle )
The base class constructor
The base class constructor
Parameters
- $handle
- Image handle (GD2 resource)
|
public
|
#
__destruct( )
Cleanup
Destroys the handle via WideImage_Image::destroy() when called by the GC.
|
public
|
#
destroy( )
This method destroy the image handle, and releases the image resource.
This method destroy the image handle, and releases the image resource.
After this is called, the object doesn't hold a valid image any more.
No operation should be called after that.
|
public
resource
|
#
getHandle( )
Returns the GD image resource
Returns the GD image resource
Returns
resource GD image resource
|
public
boolean
|
#
isValid( )
Returns
boolean True, if the image object holds a valid GD image, false otherwise
|
public
|
|
public
|
#
saveToFile( string $uri )
Saves an image to a file
The file type is recognized from the $uri. If you save to a GIF8, truecolor images
are automatically converted to palette.
This method supports additional parameters: quality (for jpeg images) and
compression quality and filters (for png images). See http://www.php.net/imagejpeg and
http://www.php.net/imagepng for details.
Examples:
$image->saveToFile('image.gif');
$image->saveToFile('image.png', 7, PNG_NO_FILTER);
$image->saveToFile('image.jpg', 80);
$image->saveToFile('image.jpg');
Parameters
|
public
string
|
#
asString( string $format )
Returns binary string with image data in format specified by $format
Returns binary string with image data in format specified by $format
Additional parameters may be passed to the function. See WideImage_Image::saveToFile() for more details.
Parameters
- $format
- The format of the image
Returns
string The binary image data in specified format
|
public
|
#
output( string $format )
Outputs the image to browser
Outputs the image to browser
Sets headers Content-length and Content-type, and echoes the image in the specified format.
All other headers (such as Content-disposition) must be added manually.
Example:
WideImage::load('image1.png')->resize(100, 100)->output('gif');
Parameters
|
public
integer
|
|
public
integer
|
|
public
integer
|
#
allocateColor( mixed $R, integer $G = null, integer $B = null )
Allocate a color by RGB values.
Allocate a color by RGB values.
Parameters
- $R
- Red-component value or an RGB array (with red, green, blue keys)
- $G
- If $R is int, this is the green component
- $B
- If $R is int, this is the blue component
Returns
integer Image color index
|
public
boolean
|
#
isTransparent( )
Returns
boolean True if the image is transparent, false otherwise
|
public
integer
|
|
public
|
#
setTransparentColor( integer $color )
Sets the current transparent color index. Only makes sense for palette images (8-bit).
Sets the current transparent color index. Only makes sense for palette images (8-bit).
Parameters
- $color
- Transparent color index
|
public
mixed
|
#
getTransparentColorRGB( )
Returns a RGB array of the transparent color or null if none.
Returns a RGB array of the transparent color or null if none.
Returns
mixed Transparent color RGBA array
|
public
array
|
#
getRGBAt( integer $x, integer $y )
Returns a RGBA array for pixel at $x, $y
Returns a RGBA array for pixel at $x, $y
Parameters
Returns
array RGB array
|
public
|
#
setRGBAt( integer $x, integer $y, array $color )
Writes a pixel at the designated coordinates
Writes a pixel at the designated coordinates
Takes an associative array of colours and uses getExactColor() to
retrieve the exact index color to write to the image with.
Parameters
|
public
mixed
|
#
getColorRGB( integer $colorIndex )
Returns a color's RGB
Parameters
Returns
mixed RGBA array for a color with index $colorIndex
|
public
integer
|
#
getColorAt( integer $x, integer $y )
Returns an index of the color at $x, $y
Returns an index of the color at $x, $y
Parameters
Returns
integer Color index for a pixel at $x, $y
|
public
|
#
setColorAt( integer $x, integer $y, integer $color )
Set the color index $color to a pixel at $x, $y
Set the color index $color to a pixel at $x, $y
Parameters
|
public
integer
|
#
getClosestColor( mixed $R, integer $G = null, integer $B = null )
Returns closest color index that matches the given RGB value. Uses
PHP's imagecolorclosest()
Returns closest color index that matches the given RGB value. Uses
PHP's imagecolorclosest()
Parameters
- $R
- Red or RGBA array
- $G
- Green component (or null if $R is an RGB array)
- $B
- Blue component (or null if $R is an RGB array)
Returns
integer Color index
|
public
integer
|
#
getExactColor( mixed $R, integer $G = null, integer $B = null )
Returns the color index that exactly matches the given RGB value. Uses
PHP's imagecolorexact()
Returns the color index that exactly matches the given RGB value. Uses
PHP's imagecolorexact()
Parameters
- $R
- Red or RGBA array
- $G
- Green component (or null if $R is an RGB array)
- $B
- Blue component (or null if $R is an RGB array)
Returns
integer Color index
|
public
|
#
copyTransparencyFrom( object $sourceImage, boolean $fill = true )
Copies transparency information from $sourceImage. Optionally fills
the image with the transparent color at (0, 0).
Copies transparency information from $sourceImage. Optionally fills
the image with the transparent color at (0, 0).
Parameters
- $sourceImage
- $fill
- True if you want to fill the image with transparent color
|
public
|
#
fill( integer $x, integer $y, integer $color )
Fill the image at ($x, $y) with color index $color
Fill the image at ($x, $y) with color index $color
Parameters
|
protected
object
|
#
getOperation( string $name )
Used internally to create Operation objects
Used internally to create Operation objects
Parameters
Returns
object
|
public
WideImage_Image
|
#
getMask( )
Returns the image's mask
Mask is a greyscale image where the shade defines the alpha channel (black = transparent, white = opaque).
For opaque images (JPEG), the result will be white. For images with single-color transparency (GIF, 8-bit PNG),
the areas with the transparent color will be black. For images with alpha channel transparenct,
the result will be alpha channel.
Returns
|
public
WideImage_Image
|
#
resize( mixed $width = null, mixed $height = null, string $fit = 'inside', string $scale = 'any' )
Resize the image to given dimensions.
Resize the image to given dimensions.
$width and $height are both smart coordinates. This means that you can pass any of these values in: - positive or negative integer (100, -20, ...) - positive or negative percent string (30%, -15%, ...) - complex coordinate (50% - 20, 15 + 30%, ...)
If $width is null, it's calculated proportionally from $height, and vice versa.
Example (resize to half-size):
$smaller = $image->resize('50%');
$smaller = $image->resize('100', '100', 'inside', 'down');
is the same as
$smaller = $image->resizeDown(100, 100, 'inside');
Parameters
- $width
- The new width (smart coordinate), or null.
- $height
- The new height (smart coordinate), or null.
- $fit
- 'inside', 'outside', 'fill'
- $scale
- 'down', 'up', 'any'
Returns
|
public
WideImage_Image
|
#
resizeDown( integer $width = null, integer $height = null, string $fit = 'inside' )
Same as WideImage_Image::resize(), but the image is only applied if it is larger then the given dimensions.
Otherwise, the resulting image retains the source's dimensions.
Same as WideImage_Image::resize(), but the image is only applied if it is larger then the given dimensions.
Otherwise, the resulting image retains the source's dimensions.
Parameters
- $width
- New width, smart coordinate
- $height
- New height, smart coordinate
- $fit
- 'inside', 'outside', 'fill'
Returns
|
public
WideImage_Image
|
#
resizeUp( integer $width = null, integer $height = null, string $fit = 'inside' )
Same as WideImage_Image::resize(), but the image is only applied if it is smaller then the given dimensions.
Otherwise, the resulting image retains the source's dimensions.
Same as WideImage_Image::resize(), but the image is only applied if it is smaller then the given dimensions.
Otherwise, the resulting image retains the source's dimensions.
Parameters
- $width
- New width, smart coordinate
- $height
- New height, smart coordinate
- $fit
- 'inside', 'outside', 'fill'
Returns
|
public
WideImage_Image
|
#
rotate( integer $angle, integer $bgColor = null, boolean $ignoreTransparent = true )
Rotate the image for angle $angle clockwise.
Rotate the image for angle $angle clockwise.
Preserves transparency. Has issues when saving to a BMP.
Parameters
- $angle
- Angle in degrees, clock-wise
- $bgColor
- color of the new background
- $ignoreTransparent
Returns
|
public
WideImage_Image
|
#
merge( WideImage_Image $overlay, mixed $left = 0, mixed $top = 0, integer $pct = 100 )
This method lays the overlay (watermark) on the image.
This method lays the overlay (watermark) on the image.
Hint: if the overlay is a truecolor image with alpha channel, you should leave $pct at 100.
This operation supports alignment notation in coordinates:
$watermark = WideImage::load('logo.gif');
$base = WideImage::load('picture.jpg');
$result = $base->merge($watermark, "right - 10", "bottom - 10", 50);
Parameters
- $overlay
- The overlay image
- $left
- Left position of the overlay, smart coordinate
- $top
- Top position of the overlay, smart coordinate
- $pct
- The opacity of the overlay
Returns
|
public
WideImage_Image
|
#
resizeCanvas( mixed $width, mixed $height, mixed $pos_x, mixed $pos_y, integer $bg_color = null, string $scale = 'any', boolean $merge = false )
Resizes the canvas of the image, but doesn't scale the content of the image
Resizes the canvas of the image, but doesn't scale the content of the image
This operation creates an empty canvas with dimensions $width x $height, filled with
background color $bg_color and draws the original image onto it at position [$pos_x, $pos_y].
Arguments $width, $height, $pos_x and $pos_y are all smart coordinates. $width and $height are
relative to the current image size, $pos_x and $pos_y are relative to the newly calculated
canvas size. This can be confusing, but it makes sense. See the example below.
The example below loads a 100x150 image and then resizes its canvas to 200% x 100%+20
(which evaluates to 200x170). The image is placed at position [10, center+20], which evaluates to [10, 30].
$image = WideImage::load('someimage.jpg');
$white = $image->allocateColor(255, 255, 255);
$image->resizeCanvas('200%', '100% + 20', 10, 'center+20', $white);
The parameter $merge defines whether the original image should be merged onto the new canvas.
This means it blends transparent color and alpha colors into the background color. If set to false,
the original image is just copied over, preserving the transparency/alpha information.
You can set the $scale parameter to limit when to resize the canvas. For example, if you want
to resize the canvas only if the image is smaller than the new size, but leave the image intact
if it's larger, set it to 'up'. Likewise, if you want to shrink the canvas, but don't want to
change images that are already smaller, set it to 'down'.
Parameters
- $width
- Width of the new canvas (smart coordinate, relative to current image width)
- $height
- Height of the new canvas (smart coordinate, relative to current image height)
- $pos_x
- x-position of the image (smart coordinate, relative to the new width)
- $pos_y
- y-position of the image (smart coordinate, relative to the new height)
- $bg_color
- Background color (created with allocateColor or allocateColorAlpha), defaults to null (tries to use a transparent color)
- $scale
- Possible values: 'up' (enlarge only), 'down' (downsize only), 'any' (resize precisely to $width x $height). Defaults to 'any'.
- $merge
- Merge the original image (flatten alpha channel and transparency) or copy it over (preserve). Defaults to false.
Returns
|
public
WideImage_Image
|
#
roundCorners( integer $radius, integer $color = null, integer $smoothness = 2, integer $corners = 255 )
Returns an image with round corners
Returns an image with round corners
You can either set the corners' color or set them transparent.
Note on $smoothness: 1 means jagged edges, 2 is much better, more than 4 doesn't noticeably improve the quality.
Rendering becomes increasingly slower if you increase smoothness.
Example:
$nice = $ugly->roundCorners(20, $ugly->allocateColor(255, 0, 0), 2);
Use $corners parameter to specify which corners to draw rounded. Possible values are
WideImage::SIDE_TOP_LEFT, WideImage::SIDE_TOP,
WideImage::SIDE_TOP_RIGHT, WideImage::SIDE_RIGHT,
WideImage::SIDE_BOTTOM_RIGHT, WideImage::SIDE_BOTTOM,
WideImage::SIDE_BOTTOM_LEFT, WideImage::SIDE_LEFT, and WideImage::SIDE_ALL.
You can specify any combination of corners with a + operation, see example below.
Example:
$white = $image->allocateColor(255, 255, 255);
$diagonal_corners = $image->roundCorners(15, $white, 2, WideImage::SIDE_TOP_LEFT + WideImage::SIDE_BOTTOM_RIGHT);
$right_corners = $image->roundCorners(15, $white, 2, WideImage::SIDE_RIGHT);
Parameters
- $radius
- Radius of the corners
- $color
- The color of corners. If null, corners are rendered transparent (slower than using a solid color).
- $smoothness
- Specify the level of smoothness. Suggested values from 1 to 4.
- $corners
- Specify which corners to draw (defaults to WideImage::SIDE_ALL = all corners)
Returns
|
public
WideImage_Image
|
#
applyMask( WideImage_Image $mask, mixed $left = 0, mixed $top = 0 )
Returns an image with applied mask
Returns an image with applied mask
A mask is a grayscale image, where the shade determines the alpha channel. Black is fully transparent
and white is fully opaque.
Parameters
- $mask
- The mask image, greyscale
- $left
- Left coordinate, smart coordinate
- $top
- Top coordinate, smart coordinate
Returns
|
public
WideImage_Image
|
#
applyFilter( integer $filter, integer $arg1 = null, integer $arg2 = null, integer $arg3 = null, integer $arg4 = null )
Applies a filter
Parameters
- $filter
- One of the IMG_FILTER_* constants
- $arg1
- $arg2
- $arg3
- $arg4
Returns
|
public
WideImage_Image
|
#
applyConvolution( array $matrix, float $div, float $offset )
Applies convolution matrix with imageconvolution()
Applies convolution matrix with imageconvolution()
Parameters
Returns
|
public
WideImage_Image
|
#
crop( mixed $left = 0, mixed $top = 0, mixed $width = '100%', mixed $height = '100%' )
Returns a cropped rectangular portion of the image
Returns a cropped rectangular portion of the image
If the rectangle specifies area that is out of bounds, it's limited to the current image bounds.
Examples:
$cropped = $img->crop(10, 10, 150, 200);
$cropped = $img->crop(-100, -50, 100, 50);
$cropped = $img->crop('25%', '25%', '50%', '50%');
This operation supports alignment notation in left/top coordinates.
Example:
$cropped = $img->crop("right", "bottom", 100, 200);
$cropped = $img->crop("center", "middle", 50, 30);
Parameters
- $left
- Left-coordinate of the crop rect, smart coordinate
- $top
- Top-coordinate of the crop rect, smart coordinate
- $width
- Width of the crop rect, smart coordinate
- $height
- Height of the crop rect, smart coordinate
Returns
|
public
WideImage_Image
|
#
autoCrop( integer $margin = 0, integer $rgb_threshold = 0, integer $pixel_cutoff = 1, integer $base_color = null )
Performs an auto-crop on the image
Performs an auto-crop on the image
The image is auto-cropped from each of four sides. All sides are
scanned for pixels that differ from $base_color for more than
$rgb_threshold in absolute RGB difference. If more than $pixel_cutoff
differentiating pixels are found, that line is considered to be the crop line for the side.
If the line isn't different enough, the algorithm procedes to the next line
towards the other edge of the image.
When the crop rectangle is found, it's enlarged by the $margin value on each of the four sides.
Parameters
- $margin
- Margin for the crop rectangle, can be negative.
- $rgb_threshold
- RGB difference which still counts as "same color".
- $pixel_cutoff
- How many pixels need to be different to mark a cut line.
- $base_color
- The base color index. If none specified (or null given), left-top pixel is used.
Returns
|
public
WideImage_Image
|
#
asNegative( )
Returns a negative of the image
Returns a negative of the image
This operation differs from calling WideImage_Image::applyFilter(IMG_FILTER_NEGATIVE), because it's 8-bit and transparency safe.
This means it will return an 8-bit image, if the source image is 8-bit. If that 8-bit image has a palette transparency,
the resulting image will keep transparency.
Returns
|
public
WideImage_Image
|
#
asGrayscale( )
Returns a grayscale copy of the image
Returns a grayscale copy of the image
Returns
|
public
WideImage_Image
|
#
mirror( )
Returns a mirrored copy of the image
Returns a mirrored copy of the image
Returns
|
public
WideImage_Image
|
#
unsharp( float $amount, float $radius, float $threshold )
Applies the unsharp filter
Applies the unsharp filter
Parameters
- $amount
- $radius
- $threshold
Returns
|
public
WideImage_Image
|
#
flip( )
Returns a flipped (mirrored over horizontal line) copy of the image
Returns a flipped (mirrored over horizontal line) copy of the image
Returns
|
public
WideImage_Image
|
#
correctGamma( float $inputGamma, float $outputGamma )
Corrects gamma on the image
Corrects gamma on the image
Parameters
Returns
|
public
WideImage_Image
|
#
addNoise( integer $amount, string $type )
Adds noise to the image
Parameters
- $amount
- Number of noise pixels to add
- $type
- Type of noise 'salt&pepper', 'color' or 'mono'
Returns
Author
Tomasz Kapusta
|
public
WideImage_Image
|
#
__call( string $name, array $args )
Used internally to execute operations
Used internally to execute operations
Parameters
Returns
|
public
string
|
#
__toString( )
Returns an image in GIF or PNG format
Returns an image in GIF or PNG format
Returns
string
|
public
WideImage_Image
|
#
copy( )
Returns a copy of the image object
Returns a copy of the image object
Returns
|
public
|
#
copyTo( WideImage_Image $dest, integer $left = 0, integer $top = 0 )
Copies this image onto another image
Copies this image onto another image
Parameters
|
public
WideImage_Canvas
|
#
getCanvas( )
Returns the canvas object
Returns the canvas object
The Canvas object can be used to draw text and shapes on the image
Examples:
$img = WideImage::load('pic.jpg);
$canvas = $img->getCanvas();
$canvas->useFont('arial.ttf', 15, $img->allocateColor(200, 220, 255));
$canvas->writeText(10, 50, "Hello world!");
$canvas->filledRectangle(10, 10, 80, 40, $img->allocateColor(255, 127, 255));
$canvas->line(60, 80, 30, 100, $img->allocateColor(255, 0, 0));
$img->saveToFile('new.png');
Returns
|
abstract public
boolean
|
#
isTrueColor( )
Returns true if the image is true-color, false otherwise
Returns true if the image is true-color, false otherwise
Returns
boolean
|
abstract public
WideImage_TrueColorImage
|
#
asTrueColor( )
Returns a true-color copy of the image
Returns a true-color copy of the image
Returns
|
abstract public
WideImage_Image
|
#
asPalette( integer $nColors = 255, boolean $dither = null, boolean $matchPalette = true )
Returns a palette copy (8bit) of the image
Returns a palette copy (8bit) of the image
Parameters
- $nColors
- Number of colors in the resulting image, more than 0, less or equal to 255
- $dither
- Use dithering or not
- $matchPalette
- Set to true to use imagecolormatch() to match the resulting palette more closely to the original image
Returns
|
abstract public
WideImage_Image
|
#
getChannels( )
Retrieve an image with selected channels
Retrieve an image with selected channels
Examples:
$channels = $img->getChannels('red', 'blue');
$channels = $img->getChannels('alpha', 'green');
$channels = $img->getChannels(array('green', 'blue'));
Returns
|
abstract public
WideImage_Image
|
#
copyNoAlpha( )
Returns an image without an alpha channel
Returns an image without an alpha channel
Returns
|
public
array
|
#
__sleep( )
Returns an array of serializable protected variables. Called automatically upon serialize().
Returns an array of serializable protected variables. Called automatically upon serialize().
Returns
array
|
public
|
#
__wakeup( )
Restores an image from serialization. Called automatically upon unserialize().
Restores an image from serialization. Called automatically upon unserialize().
|