Class: WideImage_Image
Source Location: /Image.php
Base class for images
Author(s):
|
|
|
Class Details
Class Variables
Class Methods
constructor __construct [line 74]
destructor __destruct [line 85]
Cleanup Destroys the handle via WideImage_Image::destroy() when called by the GC.
method addNoise [line 813]
Adds noise to the image
Tags:
Parameters:
method allocateColor [line 248]
int allocateColor(
mixed
$R, [int
$G = null], [int
$B = null])
|
|
Allocate a color by RGB values.
Tags:
Parameters:
method applyConvolution [line 677]
WideImage_Image applyConvolution(
array
$matrix, float
$div, float
$offset)
|
|
Applies convolution matrix with imageconvolution()
Parameters:
method applyFilter [line 664]
WideImage_Image applyFilter(
int
$filter, [int
$arg1 = null], [int
$arg2 = null], [int
$arg3 = null], [int
$arg4 = null])
|
|
Applies a filter
Parameters:
method applyMask [line 649]
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.
Tags:
Parameters:
method asGrayscale [line 754]
Returns a grayscale copy of the image
Tags:
method asNegative [line 744]
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.
Tags:
method asPalette [line 919]
method asString [line 175]
string asString(
string
$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.
Tags:
Parameters:
method asTrueColor [line 909]
method autoCrop [line 730]
WideImage_Image autoCrop(
[int
$margin = 0], [int
$rgb_threshold = 0], [int
$pixel_cutoff = 1], [int
$base_color = null])
|
|
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.
Tags:
Parameters:
method copy [line 850]
Returns a copy of the image object
Tags:
method copyNoAlpha [line 940]
method copyTo [line 865]
Copies this image onto another image
Parameters:
method copyTransparencyFrom [line 401]
void copyTransparencyFrom(
object
$sourceImage, [bool
$fill = true])
|
|
Copies transparency information from $sourceImage. Optionally fills the image with the transparent color at (0, 0).
Parameters:
method correctGamma [line 799]
Corrects gamma on the image
Tags:
Parameters:
method crop [line 707]
WideImage_Image crop(
[mixed
$left = 0], [mixed
$top = 0], [mixed
$width = '100%'], [mixed
$height = '100%'])
|
|
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); // crops a 150x200 rect at (10, 10)
$cropped = $img->crop(- 100, - 50, 100, 50); // crops a 100x50 rect at the right-bottom of the image
$cropped = $img->crop('25%', '25%', '50%', '50%'); // crops a 50%x50% rect from the center of the image
This operation supports alignment notation in left/top coordinates. Example: $cropped = $img->crop("right", "bottom", 100, 200); // crops a 100x200 rect from right bottom
$cropped = $img->crop("center", "middle", 50, 30); // crops a 50x30 from the center of the image
Tags:
Parameters:
method destroy [line 96]
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.
method fill [line 430]
void fill(
int
$x, int
$y, int
$color)
|
|
Fill the image at ($x, $y) with color index $color
Parameters:
method flip [line 787]
Returns a flipped (mirrored over horizontal line) copy of the image
Tags:
method getCanvas [line 890]
Returns the canvas object The Canvas object can be used to draw text and shapes on the image Examples:
$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');
Tags:
method getChannels [line 933]
method getClosestColor [line 369]
int getClosestColor(
mixed
$R, [int
$G = null], [int
$B = null])
|
|
Returns closest color index that matches the given RGB value. Uses PHP's imagecolorclosest()
Tags:
Parameters:
method getColorAt [line 343]
int getColorAt(
int
$x, int
$y)
|
|
Returns an index of the color at $x, $y
Tags:
Parameters:
method getColorRGB [line 331]
mixed getColorRGB(
int
$colorIndex)
|
|
Returns a color's RGB
Tags:
Parameters:
method getExactColor [line 386]
int getExactColor(
mixed
$R, [int
$G = null], [int
$B = null])
|
|
Returns the color index that exactly matches the given RGB value. Uses PHP's imagecolorexact()
Tags:
Parameters:
method getHandle [line 109]
Returns the GD image resource
Tags:
method getHeight [line 235]
method getMask [line 457]
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.
Tags:
method getOperation [line 441]
object getOperation(
string
$name)
|
|
Used internally to create Operation objects
Tags:
Parameters:
method getRGBAt [line 305]
array getRGBAt(
int
$x, int
$y)
|
|
Returns a RGBA array for pixel at $x, $y
Tags:
Parameters:
method getTransparentColor [line 267]
int getTransparentColor(
)
|
|
Tags:
method getTransparentColorRGB [line 287]
mixed getTransparentColorRGB(
)
|
|
Returns a RGB array of the transparent color or null if none.
Tags:
method getWidth [line 227]
method isTransparent [line 259]
method isTrueColor [line 902]
method isValid [line 117]
method merge [line 554]
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:
$result = $base->merge($watermark, "right - 10", "bottom - 10", 50);
// applies a logo aligned to bottom-right corner with a 10 pixel margin
Tags:
Parameters:
method mirror [line 764]
Returns a mirrored copy of the image
Tags:
method output [line 214]
void output(
string
$format)
|
|
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:
Parameters:
method releaseHandle [line 125]
method resize [line 487]
WideImage_Image resize(
[mixed
$width = null], [mixed
$height = null], [string
$fit = 'inside'], [string
$scale = 'any'])
|
|
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');
Tags:
Parameters:
method resizeCanvas [line 595]
WideImage_Image resizeCanvas(
mixed
$width, mixed
$height, mixed
$pos_x, mixed
$pos_y, [int
$bg_color = null], [string
$scale = 'any'], [bool
$merge = false])
|
|
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->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'.
Tags:
Parameters:
method resizeDown [line 501]
WideImage_Image resizeDown(
[int
$width = null], [int
$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.
Tags:
Parameters:
method resizeUp [line 515]
WideImage_Image resizeUp(
[int
$width = null], [int
$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.
Tags:
Parameters:
method rotate [line 530]
WideImage_Image rotate(
int
$angle, [int
$bgColor = null], [bool
$ignoreTransparent = true])
|
|
Rotate the image for angle $angle clockwise. Preserves transparency. Has issues when saving to a BMP.
Tags:
Parameters:
method roundCorners [line 633]
WideImage_Image roundCorners(
int
$radius, [int
$color = null], [int
$smoothness = 2], [int
$corners = 255])
|
|
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:
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:
Tags:
Parameters:
method saveToFile [line 157]
void 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: // save to a GIF
// save to a PNG with compression=7 and no filters
$image->saveToFile('image.png', 7, PNG_NO_FILTER);
// save to a JPEG with quality=80
// save to a JPEG with default quality=100
Parameters:
method setColorAt [line 355]
void setColorAt(
int
$x, int
$y, int
$color)
|
|
Set the color index $color to a pixel at $x, $y
Parameters:
method setRGBAt [line 320]
void setRGBAt(
int
$x, int
$y, array
$color)
|
|
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:
method setTransparentColor [line 277]
void setTransparentColor(
int
$color)
|
|
Sets the current transparent color index. Only makes sense for palette images (8-bit).
Parameters:
method unsharp [line 777]
Applies the unsharp filter
Tags:
Parameters:
method writeHeader [line 196]
void writeHeader(
$name
$name, $data
$data)
|
|
Output a header to browser.
Tags:
Parameters:
method __call [line 825]
Used internally to execute operations
Parameters:
method __sleep [line 947]
Returns an array of serializable protected variables. Called automatically upon serialize().
method __toString [line 837]
Returns an image in GIF or PNG format
method __wakeup [line 956]
Restores an image from serialization. Called automatically upon unserialize().
|
|