XOOPS API 2.5.11 Beta1  UI v0.5
Réalisé par monxoops.fr
Référence de la classe Image
+ Graphe d'héritage de Image:

Fonctions membres publiques

 __construct ($handle)
 
 __destruct ()
 
 destroy ()
 
 getHandle ()
 
 isValid ()
 
 releaseHandle ()
 
 saveToFile ($uri)
 
 asString ($format)
 
 output ($format)
 
 getWidth ()
 
 getHeight ()
 
 allocateColor ($R, $G=null, $B=null)
 
 isTransparent ()
 
 getTransparentColor ()
 
 setTransparentColor ($color)
 
 getTransparentColorRGB ()
 
 getRGBAt ($x, $y)
 
 setRGBAt ($x, $y, $color)
 
 getColorRGB ($colorIndex)
 
 getColorAt ($x, $y)
 
 setColorAt ($x, $y, $color)
 
 getClosestColor ($R, $G=null, $B=null)
 
 getExactColor ($R, $G=null, $B=null)
 
 copyTransparencyFrom ($sourceImage, $fill=true)
 
 fill ($x, $y, $color)
 
 getMask ()
 
 resize ($width=null, $height=null, $fit='inside', $scale='any')
 
 resizeDown ($width=null, $height=null, $fit='inside')
 
 resizeUp ($width=null, $height=null, $fit='inside')
 
 rotate ($angle, $bgColor=null, $ignoreTransparent=true)
 
 merge ($overlay, $left=0, $top=0, $pct=100)
 
 resizeCanvas ($width, $height, $pos_x, $pos_y, $bg_color=null, $scale='any', $merge=false)
 
 roundCorners ($radius, $color=null, $smoothness=2, $corners=255)
 
 applyMask ($mask, $left=0, $top=0)
 
 applyFilter ($filter, $arg1=null, $arg2=null, $arg3=null, $arg4=null)
 
 applyConvolution ($matrix, $div, $offset)
 
 crop ($left=0, $top=0, $width='100%', $height='100%')
 
 autoCrop ($margin=0, $rgb_threshold=0, $pixel_cutoff=1, $base_color=null)
 
 asNegative ()
 
 asGrayscale ()
 
 mirror ()
 
 unsharp ($amount, $radius, $threshold)
 
 flip ()
 
 correctGamma ($inputGamma, $outputGamma)
 
 addNoise ($amount, $type)
 
 __call ($name, $args)
 
 __toString ()
 
 copy ()
 
 copyTo ($dest, $left=0, $top=0)
 
 getCanvas ()
 
 isTrueColor ()
 
 asTrueColor ()
 
 asPalette ($nColors=255, $dither=null, $matchPalette=true)
 
 getChannels ()
 
 copyNoAlpha ()
 
 __sleep ()
 
 __wakeup ()
 

Fonctions membres protégées

 writeHeader ($name, $data)
 
 getOperation ($name)
 

Attributs protégés

 $handle = null
 
 $handleReleased = false
 
 $canvas = null
 
 $sdata = null
 

Documentation des constructeurs et destructeur

◆ __construct()

__construct (   $handle)

The base class constructor

Paramètres
resource$handleImage handle (GD2 resource)

Réimplémentée dans TrueColorImage.

◆ __destruct()

__destruct ( )

Cleanup

Destroys the handle via \WideImage\Image::destroy() when called by the GC.

Documentation des fonctions membres

◆ __call()

__call (   $name,
  $args 
)

Used internally to execute operations

Paramètres
string$name
array$args
Renvoie
\WideImage\Image

◆ __sleep()

__sleep ( )

Returns an array of serializable protected variables. Called automatically upon serialize().

Renvoie
array

◆ __toString()

__toString ( )

Returns an image in GIF or PNG format

Renvoie
string

◆ __wakeup()

__wakeup ( )

Restores an image from serialization. Called automatically upon unserialize().

◆ addNoise()

addNoise (   $amount,
  $type 
)

Adds noise to the image

Auteur
Tomasz Kapusta
Paramètres
int$amountNumber of noise pixels to add
string$typeType of noise 'salt&pepper', 'color' or 'mono'
Renvoie
\WideImage\Image Image with noise added

◆ allocateColor()

allocateColor (   $R,
  $G = null,
  $B = null 
)

Allocate a color by RGB values.

Paramètres
mixed$RRed-component value or an RGB array (with red, green, blue keys)
int$GIf $R is int, this is the green component
int$BIf $R is int, this is the blue component
Renvoie
int Image color index

◆ applyConvolution()

applyConvolution (   $matrix,
  $div,
  $offset 
)

Applies convolution matrix with imageconvolution()

Paramètres
array$matrix
float$div
float$offset
Renvoie
\WideImage\Image

◆ applyFilter()

applyFilter (   $filter,
  $arg1 = null,
  $arg2 = null,
  $arg3 = null,
  $arg4 = null 
)

Applies a filter

Paramètres
int$filterOne of the IMG_FILTER_* constants
int$arg1
int$arg2
int$arg3
int$arg4
Renvoie
\WideImage\Image

◆ applyMask()

applyMask (   $mask,
  $left = 0,
  $top = 0 
)

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.

Paramètres
\WideImage\Image$maskThe mask image, greyscale
mixed$leftLeft coordinate, smart coordinate
mixed$topTop coordinate, smart coordinate
Renvoie
\WideImage\Image The resulting image

◆ asGrayscale()

asGrayscale ( )

Returns a grayscale copy of the image

Renvoie
\WideImage\Image grayscale copy

◆ asNegative()

asNegative ( )

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.

Renvoie
\WideImage\Image negative of the image

◆ asPalette()

asPalette (   $nColors = 255,
  $dither = null,
  $matchPalette = true 
)
abstract

Returns a palette copy (8bit) of the image

Paramètres
int$nColorsNumber of colors in the resulting image, more than 0, less or equal to 255
bool$ditherUse dithering or not
bool$matchPaletteSet to true to use imagecolormatch() to match the resulting palette more closely to the original image
Renvoie
\WideImage\Image

Réimplémentée dans TrueColorImage, et PaletteImage.

◆ asString()

asString (   $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.

Paramètres
string$formatThe format of the image
Renvoie
string The binary image data in specified format

◆ asTrueColor()

asTrueColor ( )
abstract

Returns a true-color copy of the image

Renvoie
\WideImage\TrueColorImage

Réimplémentée dans TrueColorImage, et PaletteImage.

◆ autoCrop()

autoCrop (   $margin = 0,
  $rgb_threshold = 0,
  $pixel_cutoff = 1,
  $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.

Paramètres
int$marginMargin for the crop rectangle, can be negative.
int$rgb_thresholdRGB difference which still counts as "same color".
int$pixel_cutoffHow many pixels need to be different to mark a cut line.
int$base_colorThe base color index. If none specified (or null given), left-top pixel is used.
Renvoie
\WideImage\Image The cropped image

◆ copy()

copy ( )

Returns a copy of the image object

Renvoie
\WideImage\Image The copy

◆ copyNoAlpha()

copyNoAlpha ( )
abstract

Returns an image without an alpha channel

Renvoie
\WideImage\Image

Réimplémentée dans TrueColorImage, et PaletteImage.

◆ copyTo()

copyTo (   $dest,
  $left = 0,
  $top = 0 
)

Copies this image onto another image

Paramètres
\WideImage\Image$dest
int$left
int$top

◆ copyTransparencyFrom()

copyTransparencyFrom (   $sourceImage,
  $fill = true 
)

Copies transparency information from $sourceImage. Optionally fills the image with the transparent color at (0, 0).

Paramètres
object$sourceImage
bool$fillTrue if you want to fill the image with transparent color

◆ correctGamma()

correctGamma (   $inputGamma,
  $outputGamma 
)

Corrects gamma on the image

Paramètres
float$inputGamma
float$outputGamma
Renvoie
\WideImage\Image Image with corrected gamma

◆ crop()

crop (   $left = 0,
  $top = 0,
  $width = '100%',
  $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 50x50% 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

Paramètres
mixed$leftLeft-coordinate of the crop rect, smart coordinate
mixed$topTop-coordinate of the crop rect, smart coordinate
mixed$widthWidth of the crop rect, smart coordinate
mixed$heightHeight of the crop rect, smart coordinate
Renvoie
\WideImage\Image The cropped image

◆ destroy()

destroy ( )

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.

◆ fill()

fill (   $x,
  $y,
  $color 
)

Fill the image at ($x, $y) with color index $color

Paramètres
int$x
int$y
int$color

◆ flip()

flip ( )

Returns a flipped (mirrored over horizontal line) copy of the image

Renvoie
\WideImage\Image Flipped copy

◆ getCanvas()

getCanvas ( )

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');

Renvoie
\WideImage\Canvas The Canvas object

◆ getChannels()

getChannels ( )
abstract

Retrieve an image with selected channels

Examples: $channels = $img->getChannels('red', 'blue'); $channels = $img->getChannels('alpha', 'green'); $channels = $img->getChannels(array('green', 'blue'));

Renvoie
\WideImage\Image

Réimplémentée dans TrueColorImage, et PaletteImage.

◆ getClosestColor()

getClosestColor (   $R,
  $G = null,
  $B = null 
)

Returns closest color index that matches the given RGB value. Uses PHP's imagecolorclosest()

Paramètres
mixed$RRed or RGBA array
int$GGreen component (or null if $R is an RGB array)
int$BBlue component (or null if $R is an RGB array)
Renvoie
int Color index

◆ getColorAt()

getColorAt (   $x,
  $y 
)

Returns an index of the color at $x, $y

Paramètres
int$x
int$y
Renvoie
int Color index for a pixel at $x, $y

◆ getColorRGB()

getColorRGB (   $colorIndex)

Returns a color's RGB

Paramètres
int$colorIndexColor index
Renvoie
mixed RGBA array for a color with index $colorIndex

◆ getExactColor()

getExactColor (   $R,
  $G = null,
  $B = null 
)

Returns the color index that exactly matches the given RGB value. Uses PHP's imagecolorexact()

Paramètres
mixed$RRed or RGBA array
int$GGreen component (or null if $R is an RGB array)
int$BBlue component (or null if $R is an RGB array)
Renvoie
int Color index

◆ getHandle()

getHandle ( )

Returns the GD image resource

Renvoie
resource GD image resource

◆ getHeight()

getHeight ( )
Renvoie
int Image height

◆ getMask()

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.

Renvoie
\WideImage\Image An image mask

◆ getOperation()

getOperation (   $name)
protected

Used internally to create Operation objects

Paramètres
string$name
Renvoie
object

◆ getRGBAt()

getRGBAt (   $x,
  $y 
)

Returns a RGBA array for pixel at $x, $y

Paramètres
int$x
int$y
Renvoie
array RGB array

◆ getTransparentColor()

getTransparentColor ( )
Renvoie
int Transparent color index

◆ getTransparentColorRGB()

getTransparentColorRGB ( )

Returns a RGB array of the transparent color or null if none.

Renvoie
mixed Transparent color RGBA array

◆ getWidth()

getWidth ( )
Renvoie
int Image width

◆ isTransparent()

isTransparent ( )
Renvoie
bool True if the image is transparent, false otherwise

◆ isTrueColor()

isTrueColor ( )
abstract

Returns true if the image is true-color, false otherwise

Renvoie
bool

Réimplémentée dans TrueColorImage, et PaletteImage.

◆ isValid()

isValid ( )
Renvoie
bool True, if the image object holds a valid GD image, false otherwise

◆ merge()

merge (   $overlay,
  $left = 0,
  $top = 0,
  $pct = 100 
)

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); // applies a logo aligned to bottom-right corner with a 10 pixel margin

Paramètres
\WideImage\Image$overlayThe overlay image
mixed$leftLeft position of the overlay, smart coordinate
mixed$topTop position of the overlay, smart coordinate
int$pctThe opacity of the overlay
Renvoie
\WideImage\Image The merged image

◆ mirror()

mirror ( )

Returns a mirrored copy of the image

Renvoie
\WideImage\Image Mirrored copy

◆ output()

output (   $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: WideImage::load('image1.png')->resize(100, 100)->output('gif');

Paramètres
string$formatImage format

◆ releaseHandle()

releaseHandle ( )

Releases the handle

◆ resize()

resize (   $width = null,
  $height = null,
  $fit = 'inside',
  $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%, ...)
  • null: if one dimension is null, it's calculated proportionally from the other.

$fit parameter can be set to one of these three values:

  • 'inside': resize proportionally and fit the resulting image tightly in the $width x $height box
  • 'outside': resize proportionally and fit the resulting image tighly outside the box
  • 'fill': resize the image to fill the $width x $height box exactly

$scale parameter can be:

  • 'down': only resize the image if it's larger than the $width x $height box
  • 'up': only resize the image if it's smaller than the $width x $height box
  • 'any': resize the image

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');

Paramètres
mixed$widthThe new width (smart coordinate), or null.
mixed$heightThe new height (smart coordinate), or null.
string$fit'inside', 'outside', 'fill'
string$scale'down', 'up', 'any'
Renvoie
\WideImage\Image The resized image

◆ resizeCanvas()

resizeCanvas (   $width,
  $height,
  $pos_x,
  $pos_y,
  $bg_color = null,
  $scale = 'any',
  $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 = WideImage::load('someimage.jpg'); // 100x150 $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'.

Paramètres
mixed$widthWidth of the new canvas (smart coordinate, relative to current image width)
mixed$heightHeight of the new canvas (smart coordinate, relative to current image height)
mixed$pos_xx-position of the image (smart coordinate, relative to the new width)
mixed$pos_yy-position of the image (smart coordinate, relative to the new height)
int$bg_colorBackground color (created with allocateColor or allocateColorAlpha), defaults to null (tries to use a transparent color)
string$scalePossible values: 'up' (enlarge only), 'down' (downsize only), 'any' (resize precisely to $width x $height). Defaults to 'any'.
bool$mergeMerge the original image (flatten alpha channel and transparency) or copy it over (preserve). Defaults to false.
Renvoie
\WideImage\Image The resulting image with resized canvas

◆ resizeDown()

resizeDown (   $width = null,
  $height = null,
  $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.

Paramètres
int$widthNew width, smart coordinate
int$heightNew height, smart coordinate
string$fit'inside', 'outside', 'fill'
Renvoie
\WideImage\Image resized image

◆ resizeUp()

resizeUp (   $width = null,
  $height = null,
  $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.

Paramètres
int$widthNew width, smart coordinate
int$heightNew height, smart coordinate
string$fit'inside', 'outside', 'fill'
Renvoie
\WideImage\Image resized image

◆ rotate()

rotate (   $angle,
  $bgColor = null,
  $ignoreTransparent = true 
)

Rotate the image for angle $angle clockwise.

Preserves transparency. Has issues when saving to a BMP.

Paramètres
int$angleAngle in degrees, clock-wise
int$bgColorcolor of the new background
bool$ignoreTransparent
Renvoie
\WideImage\Image The rotated image

◆ roundCorners()

roundCorners (   $radius,
  $color = null,
  $smoothness = 2,
  $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: $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);

Paramètres
int$radiusRadius of the corners
int$colorThe color of corners. If null, corners are rendered transparent (slower than using a solid color).
int$smoothnessSpecify the level of smoothness. Suggested values from 1 to 4.
int$cornersSpecify which corners to draw (defaults to WideImage::SIDE_ALL = all corners)
Renvoie
\WideImage\Image The resulting image with round corners

◆ saveToFile()

saveToFile (   $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 $image->saveToFile('image.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 $image->saveToFile('image.jpg', 80);

// save to a JPEG with default quality=100 $image->saveToFile('image.jpg');

Paramètres
string$uriFile location

◆ setColorAt()

setColorAt (   $x,
  $y,
  $color 
)

Set the color index $color to a pixel at $x, $y

Paramètres
int$x
int$y
int$colorColor index

◆ setRGBAt()

setRGBAt (   $x,
  $y,
  $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.

Paramètres
int$x
int$y
array$color

◆ setTransparentColor()

setTransparentColor (   $color)

Sets the current transparent color index. Only makes sense for palette images (8-bit).

Paramètres
int$colorTransparent color index

◆ unsharp()

unsharp (   $amount,
  $radius,
  $threshold 
)

Applies the unsharp filter

Paramètres
float$amount
float$radius
float$threshold
Renvoie
\WideImage\Image Unsharpened copy of the image

◆ writeHeader()

writeHeader (   $name,
  $data 
)
protected

Output a header to browser.

Paramètres
$nameName of the header
$dataData

Documentation des champs

◆ $canvas

$canvas = null
protected

◆ $handle

$handle = null
protected

◆ $handleReleased

$handleReleased = false
protected

◆ $sdata

$sdata = null
protected

La documentation de cette classe a été générée à partir du fichier suivant :