back to gd 

gd.Image

generated from ../src/mod_gd/image.cpp

The image class.

Constants

Constructor

Image

Image(size, 
      trueColor = false)
 
Name Type Default Description
size Object
trueColor Boolean false
Image(x, 
      y, 
      trueColor = false)
 
Name Type Default Description
x Integer
y Integer
trueColor Boolean false

Creates a new Image. When you pass an object, they must have a width and height property.

Properties

Name Type Description
clip Object Establishes a clipping rectangle. Once clip has been set, all future drawing operations will remain within the specified clipping area, until a new clip is set. For instance, if a clipping rectangle of 25, 25, 75, 75 has been set within a 100x100 image, a diagonal line from 0,0 to 99,99 will appear only between 25,25 and 75,75. When set the object must contain the following properties: x, y, width, height (interchangeable with wxRect)

If clip is never set, the clipping area will be the entire image.
colorsTotal read only Integer Returns the number of colors currently allocated in a palette image. For truecolor images, the result of the property is undefined and should not be used.
interlace Integer interlace is used to determine whether an image should be stored in a linear fashion, in which lines will appear on the display from first to last, or in an interlaced fashion, in which the image will "fade in" over several passes. By default, images are not interlaced. (When writing JPEG images, interlacing implies generating progressive JPEG files, which are represented as a series of scans of increasing quality. Noninterlaced gd images result in regular [sequential] JPEG data streams.)

A nonzero value for interlace turns on interlace; a zero value turns it off. Note that interlace has no effect on other functions, and has no meaning unless you save the image in PNG or JPEG format; the gd and xbm formats do not support interlace.

When a PNG is loaded or a JPEG is loaded, interlace will be set according to the setting in the PNG or JPEG file.

Note that many PNG and JPEG viewers and web browsers do not support interlace or the incremental display of progressive JPEGs. However, the interlaced PNG or progressive JPEG should still display; it will simply appear all at once, just as other images do.
size read only Object Returns an object with an x and y property (interchangeable with wxSize)
tile Image
transparent Integer Returns the current transparent color index in the image. If there is no transparent color, returns -1.

Sets the transparent color index for the specified image to the specified index. To indicate that there should be no transparent color, use a color index of -1. Note that JPEG images do not support transparency, so this setting has no effect when writing JPEG images.

The color index used should be an index allocated by colorAllocate, whether explicitly invoked by your code or implicitly invoked by loading an image. In order to ensure that your image has a reasonable appearance when viewed by users who do not have transparent background capabilities (or when you are writing a JPEG-format file, which does not support transparency), be sure to give reasonable RGB values to the color you allocate for use as a transparent color, even though it will be transparent on systems that support PNG transparency.
trueColour read only Boolean Returns true if the image is a truecolour image
x read only Integer The width of the image.
y read only Integer The height of the image.

Methods

alphaBlending

alphaBlending(Blending)
 
Name Type Default Description
Blending Integer

The alphaBlending function allows for two different modes of drawing on truecolor images. In blending mode, which is on by default, the alpha channel component of the color supplied to all drawing functions, such as setPixel, determines how much of the underlying color should be allowed to shine through. As a result, gd automatically blends the existing color at that point with the drawing color, and stores the result in the image. The resulting pixel is opaque. In non-blending mode, the drawing color is copied literally with its alpha channel information, replacing the destination pixel. Blending mode is not available when drawing on palette images.

arc

arc(Center, 
    Size, 
    S, 
    E, 
    ColourIndex)
 
Name Type Default Description
Center Object An object with an x and y property
Size Object An object with a width and height property
S Integer
E Integer
ColourIndex Integer The index of an allocated color. See colorAllocate
arc(X, 
    Y, 
    Width, 
    Height, 
    S, 
    E, 
    ColourIndex)
 
Name Type Default Description
X Integer
Y Integer
Width Integer
Height Integer
S Integer
E Integer
ColourIndex Integer The index of an allocated color. See colorAllocate

arc is used to draw a partial ellipse centered at the given point, with the specified width and height in pixels. The arc begins at the position in degrees specified by S and ends at the position specified by E. The arc is drawn in the color specified by the last argument. A circle can be drawn by beginning from 0 degrees and ending at 360 degrees, with width and height being equal. E must be greater than S. Values greater than 360 are interpreted modulo 360.

blue

blue(C)
 
Name Type Default Description
C Integer

Returns the blue portion of the specified color in the image.

boundsSafe

boundsSafe(Point) : Boolean
 
Name Type Default Description
Point Object An object with an x and y property
boundsSafe(X, 
           Y) : Boolean
 
Name Type Default Description
X Integer
Y Integer

boundsSafe returns true if the specified point is within the current clipping rectangle, false if not. The clipping rectangle is set by clip and defaults to the entire image.

colorAllocate

colorAllocate(Colour)
 
Name Type Default Description
Colour Object An object with a red, green and blue property
colorAllocate(Red, 
              Green, 
              Blue)
 
Name Type Default Description
Red Integer
Green Integer
Blue Integer

colorAllocate finds the first available color index in the image, sets its RGB values to those requested, and returns the index of the new color table entry, or an RGBA value in the case of a truecolor image; in either case you can then use the returned value as a parameter to drawing functions. When creating a new palette-based image, the first time you invoke this function, you are setting the background color for that image.

In the event that all colors (256) have already been allocated, colorAllocate will return -1 to indicate failure. (This is not uncommon when working with existing PNG files that already use 256 colors.) Note that colorAllocate does not check for existing colors that match your request; see colorExact, colorClosest and colorClosestHWB for ways to locate existing colors that approximate the color desired in situations where a new color is not available. Also see colorResolve.

colorAllocateAlpha

colorAllocateAlpha(Colour, 
                   A) : Integer
 
Name Type Default Description
Colour Object An object with a red, green and blue property
A Integer
colorAllocateAlpha(Red, 
                   Green, 
                   Blue, 
                   A) : Integer
 
Name Type Default Description
Red Integer
Green Integer
Blue Integer
A Integer

colorAllocateAlpha finds the first available color index in the image specified, sets its RGBA values to those requested, and returns the index of the new color table entry, or an RGBA value in the case of a truecolor image; in either case you can then use the returned value as a parameter to drawing functions. When creating a new palette-based image, the first time you invoke this function, you are setting the background color for that image.

In the event that all colors (256) have already been allocated, colorAllocateAlpha will return -1 to indicate failure. (This is not uncommon when working with existing PNG files that already use 256 colors.) Note that colorAllocateAlpha does not check for existing colors that match your request; see colorExact, colorClosest and colorClosestHWB for ways to locate existing colors that approximate the color desired in situations where a new color is not available. Also see colorResolve

colorClosest

colorClosest(Colour)
 
Name Type Default Description
Colour Object An object with a red, green and blue property
colorClosest(Red, 
             Green, 
             Blue) : Integer
 
Name Type Default Description
Red Integer
Green Integer
Blue Integer

colorClosest searches the colors which have been defined thus far in the image specified and returns the index of the color with RGB values closest to those of the request. (Closeness is determined by Euclidian distance, which is used to determine the distance in three-dimensional color space between colors.)

If no colors have yet been allocated in the image, colorClosest returns -1.

When applied to a truecolor image, this function always succeeds in returning the desired color.

This function is most useful as a backup method for choosing a drawing color when an image already contains 256 colors and no more can be allocated. (This is not uncommon when working with existing PNG files that already use many colors.) See colorExact for a method of locating exact matches only.

colorClosestAlpha

colorClosestAlpha(Colour, 
                  A) : Integer
 
Name Type Default Description
Colour Object An object with a red, green and blue property
A Integer
colorClosestAlpha(Red, 
                  Green, 
                  Blue, 
                  A) : Integer
 
Name Type Default Description
Red Integer
Green Integer
Blue Integer
A Integer

colorClosestAlpha searches the colors which have been defined thus far in the image specified and returns the index of the color with RGBA values closest to those of the request. (Closeness is determined by Euclidian distance, which is used to determine the distance in four-dimensional color/alpha space between colors.)

If no colors have yet been allocated in the image, colorClosestAlpha returns -1.

When applied to a truecolor image, this function always succeeds in returning the desired color.

This function is most useful as a backup method for choosing a drawing color when a palette-based image already contains 256 colors and no more can be allocated. (This is not uncommon when working with existing palette-based PNG files that already use many colors.) See colorExactAlpha for a method of locating exact matches only.

colorClosestHWB

colorClosestHWB(Colour) : Integer
 
Name Type Default Description
Colour Object An object with a red, green and blue property
colorClosestHWB(Red, 
                Green, 
                Blue) : Integer
 
Name Type Default Description
Red Integer
Green Integer
Blue Integer

colorClosestHWB searches the colors which have been defined thus far in the image specified and returns the index of the color with hue, whiteness and blackness closest to the requested color. This scheme is typically superior to the Euclidian distance scheme used by colorClosest.

If no colors have yet been allocated in the image, colorClosestHWB returns -1.

When applied to a truecolor image, this function always succeeds in returning the desired color.

This function is most useful as a backup method for choosing a drawing color when a palette-based image already contains 256 colors and no more can be allocated. (This is not uncommon when working with existing palette-based PNG files that already use many colors.) See colorExactAlpha for a method of locating exact matches only.

colorDeallocate

colorDeallocate(C)
 
Name Type Default Description
C Integer Color index

colorDeallocate marks the specified color as being available for reuse. It does not attempt to determine whether the color index is still in use in the image. After a call to this function, the next call to colorAllocate for the same image will set new RGB values for that color index, changing the color of any pixels which have that index as a result. If multiple calls to colorDeallocate are made consecutively, the lowest-numbered index among them will be reused by the next colorAllocate call.

colorExact

colorExact(Colour) : Integer
 
Name Type Default Description
Colour Object An object with a red, green and blue property
colorExact(Red, 
           Green, 
           Blue) : Integer
 
Name Type Default Description
Red Integer
Green Integer
Blue Integer

colorExact searches the colors which have been defined thus far in the image specified and returns the index of the first color with RGB values which exactly match those of the request. If no allocated color matches the request precisely, colorExact returns -1. See colorClosest for a way to find the color closest to the color requested.

When applied to a truecolor image, this function always succeeds in returning the desired color.

colorResolve

colorResolve(Colour) : Integer
 
Name Type Default Description
Colour Object An object with a red, green and blue property
colorResolve(Red, 
             Green, 
             Blue) : Integer
 
Name Type Default Description
Red Integer
Green Integer
Blue Integer

colorResolve searches the colors which have been defined thus far in the image specified and returns the index of the first color with RGB values which exactly match those of the request. If no allocated color matches the request precisely, then colorResolve tries to allocate the exact color. If there is no space left in the color table then colorResolve returns the closest color (as in colorClosest). This function always returns an index of a color.

When applied to a truecolor image, this function always succeeds in returning the desired color.

colorResolveAlpha

colorResolveAlpha(Colour, 
                  A) : Integer
 
Name Type Default Description
Colour Object An object with a red, green and blue property
A Integer
colorResolveAlpha(Red, 
                  Green, 
                  Blue, 
                  A) : Integer
 
Name Type Default Description
Red Integer
Green Integer
Blue Integer
A Integer

colorResolveAlpha searches the colors which have been defined thus far in the image specified and returns the index of the first color with RGB values which exactly match those of the request. If no allocated color matches the request precisely, then colorResolveAlpha tries to allocate the exact color. If there is no space left in the color table then colorResolveAlpha returns the closest color (as in colorClosestAlpha). This function always returns an index of a color.

When applied to a truecolor image, this function always succeeds in returning the desired color.

copy

copy(Source, 
     DestPoint, 
     SourceRect)
 
Name Type Default Description
Source Image
DestPoint Object An object with an x and y property
SourceRect Object An object with an x, y, width and height property
copy(Source, 
     X, 
     Y, 
     SX, 
     SY, 
     Width, 
     Height)
 
Name Type Default Description
Source Image
X Integer Destination X
Y Integer Destination Y
SX Integer Source X
SY Integer Source Y
Width Integer
Height Integer

copy is used to copy a rectangular portion of one image to this image. (For a way of stretching or shrinking the image in the process, see copyResized) The Source argument is the source image from which the region is copied. The DestPoint specifies the point in the image to which the region will be copied. The SourceRect specifies the region in the source image.

When you copy a region from one location in an image to another location in the same image, copy will perform as expected unless the regions overlap, in which case the result is unpredictable.

Important note on copying between images: since different images do not necessarily have the same color tables, pixels are not simply set to the same color index values to copy them. copy will attempt to find an identical RGB value in the destination image for each pixel in the copied portion of the source image by invoking colorExact. If such a value is not found, copy will attempt to allocate colors as needed using colorAllocate. If both of these methods fail, copy will invoke colorClosest to find the color in the destination image which most closely approximates the color of the pixel being copied.

copyMerge

copyMerge(Source, 
          DestPoint, 
          SourceRect, 
          Angle, 
          Pct)
 
Name Type Default Description
Source Image
DestPoint Object An object with an x and y property
SourceRect Object An object with an x, y, width and height property
Angle Integer
Pct Integer
copyMerge(Source, 
          X, 
          Y, 
          SX, 
          SY, 
          Width, 
          Height, 
          Angle, 
          Pct)
 
Name Type Default Description
Source Image
X Integer Destination X
Y Integer Destination Y
SX Integer Source X
SY Integer Source Y
Width Integer
Height Integer
Angle Integer
Pct Integer

copyMerge is almost identical to copy, except that it 'merges' the two images by an amount specified in the last parameter. If the last parameter is 100, then it will function identically to copy - the source image replaces the pixels in this image.

If, however, the Pct parameter is less than 100, then the two images are merged. With Pct = 0, no action is taken.

copyMergeGray

copyMergeGray(Source, 
              DestPoint, 
              SourceRect, 
              Angle, 
              Pct)
 
Name Type Default Description
Source Image
DestPoint Object An object with an x and y property
SourceRect Object An object with an x, y, width and height property
Angle Integer
Pct Integer
copyMergeGray(Source, 
              X, 
              Y, 
              SX, 
              SY, 
              Width, 
              Height, 
              Angle, 
              Pct)
 
Name Type Default Description
Source Image
X Integer Destination X
Y Integer Destination Y
SX Integer Source X
SY Integer Source Y
Width Integer
Height Integer
Angle Integer
Pct Integer

copyMergeGray is almost identical to copyMerge, except that when merging images it preserves the hue of the source by converting the destination pixels to grey scale before the copy operation.

copyResampled

copyResampled(Source, 
              DestRect, 
              SourceRect)
 
Name Type Default Description
Source Image
DestRect wxRect
SourceRect wxRect

copyResampled is used to copy a rectangular portion of one image to this image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity. The X and Y dimensions of the original region and the destination region can vary, resulting in stretching or shrinking of the region as appropriate. (For a simpler version of this function which does not deal with resizing, see copy. For a version which does not interpolate pixel values, see copyResized.)

The Source argument is the source image from which the region is copied. The DestRect specifies the point in the image to which the region will be copied. The SourceRect specifies the region in the source image. The width and height of the source region can differ from the destination region, allowing a region to be scaled during the copying process.

When you copy a region from one location in an image to another location in the same image, copyResized will perform as expected unless the regions overlap, in which case the result is unpredictable.

Important note on copying between images: since different images do not necessarily have the same color tables, pixels are not simply set to the same color index values to copy them. copy will attempt to find an identical RGB value in the destination image for each pixel in the copied portion of the source image by invoking colorExact. If such a value is not found, copy will attempt to allocate colors as needed using colorAllocate. If both of these methods fail, copy will invoke colorClosest to find the color in the destination image which most closely approximates the color of the pixel being copied.

copyResized

copyResized(Source, 
            DestRect, 
            SourceRect)
 
Name Type Default Description
Source Image
DestRect Object An object with an x, y, width and height property
SourceRect Object An object with an x, y, width and height property
copyResized(Source, 
            X, 
            Y, 
            SX, 
            SY, 
            Width, 
            Height, 
            SWidth, 
            SHeight)
 
Name Type Default Description
Source Image
X Integer Destination X
Y Integer Destination Y
SX Integer Source X
SY Integer Source Y
Width Integer
Height Integer
SWidth Integer Source Width
SHeight Integer Source Height

copyResized is used to copy a rectangular portion of one image to this image. The X and Y dimensions of the original region and the destination region can vary, resulting in stretching or shrinking of the region as appropriate. (For a simpler version of this function which does not deal with resizing, see copy) The Source argument is the source image from which the region is copied. The DestRect specifies the point in the image to which the region will be copied. The SourceRect specifies the region in the source image. The width and height of the source region can differ from the destination region, allowing a region to be scaled during the copying process.

When you copy a region from one location in an image to another location in the same image, copyResized will perform as expected unless the regions overlap, in which case the result is unpredictable.

Important note on copying between images: since different images do not necessarily have the same color tables, pixels are not simply set to the same color index values to copy them. copy will attempt to find an identical RGB value in the destination image for each pixel in the copied portion of the source image by invoking colorExact. If such a value is not found, copy will attempt to allocate colors as needed using colorAllocate. If both of these methods fail, copy will invoke colorClosest to find the color in the destination image which most closely approximates the color of the pixel being copied.

copyRotated

copyRotated(Source, 
            DestPoint, 
            SourceRect, 
            Angle)
 
Name Type Default Description
Source Image
DestPoint Object An object with an x and y property
SourceRect Object An object with an x, y, width and height property
Angle Integer
copyRotated(Source, 
            X, 
            Y, 
            SX, 
            SY, 
            Width, 
            Height, 
            Angle)
 
Name Type Default Description
Source Image
X Integer Destination X
Y Integer Destination Y
SX Integer Source X
SY Integer Source Y
Width Integer
Height Integer
Angle Integer

copyRotated is used to copy a rectangular portion of one image to this image, or to another region of the same image. The SourceRect specifies the source area. The DestX and dstY coordinates specify the CENTER of the destination area. This important distinction is made because the rotated rectangle may or may not be parallel to the X and Y axes. The destination coordinates may be floating point, as the center of the desired destination area may lie at the center of a pixel (0.5 pixels) rather than its upper left corner. The angle specified is an integer number of degrees, between 0 and 360, with 0 degrees causing no change, and counterclockwise rotation as the angle increases.

When you copy a region from one location in an image to another location in the same image, copyRotated will perform as expected unless the regions overlap, in which case the result is unpredictable. If this presents a problem, create a scratch image in which to keep intermediate results.

Important note on copying between images: since palette-based images do not necessarily have the same color tables, pixels are not simply set to the same color index values to copy them. If the destination image is not a truecolor image, colorResolveAlpha is used to choose the destination pixel.

fill

fill(Point, 
     ColourIndex)
 
Name Type Default Description
Point Object Object with an x and y property
ColourIndex Integer The index of an allocated color. See colorAllocate
fill(X, 
     Y, 
     ColourIndex)
 
Name Type Default Description
X Integer
Y Integer
ColourIndex Integer The index of an allocated color. See colorAllocate

fill floods a portion of the image with the specified color, beginning at the specified point and flooding the surrounding region of the same color as the starting point. For a way of flooding a region defined by a specific border color rather than by its interior color, see fillToBorder.

fillToBorder

fillToBorder(Point, 
             BorderColorIndex, 
             ColourIndex)
 
Name Type Default Description
Point Object An object with a x and y property
BorderColorIndex Integer
ColourIndex Integer The index of an allocated color. See colorAllocate
fillToBorder(X, 
             Y, 
             BorderColorIndex, 
             ColourIndex)
 
Name Type Default Description
X Integer
Y Integer
BorderColorIndex Integer
ColourIndex Integer The index of an allocated color. See colorAllocate

fillToBorder floods a portion of the image with the specified color, beginning at the specified point and stopping at the specified border color. For a way of flooding an area defined by the color of the starting point, see fill. The border color cannot be a special color such as gd.Tiled; it must be a proper solid color.

filledArc

filledArc(Center, 
          Size, 
          S, 
          E, 
          ColourIndex, 
          Style)
 
Name Type Default Description
Center Object An object with an x and y property
Size Object An object with a width and height property
S Integer
E Integer
ColourIndex Integer The index of an allocated color. See colorAllocate
Style Integer
filledArc(X, 
          Y, 
          Width, 
          Height, 
          S, 
          E, 
          ColourIndex, 
          Style)
 
Name Type Default Description
X Integer
Y Integer
Width Integer
Height Integer
S Integer
E Integer
ColourIndex Integer The index of an allocated color. See colorAllocate
Style Integer

filledArc is used to draw a partial ellipse centered at the given point, with the specified width and height in pixels. The arc begins at the position in degrees specified by S and ends at the position specified by E. The arc is filled in the color specified by the second to last argument. A circle can be drawn by beginning from 0 degrees and ending at 360 degrees, with width and height being equal. E must be greater than S. Values greater than 360 are interpreted modulo 360. The last argument is a bitwise OR of the following possibilities: gd.arc, gd.chord, gd.pie (synonym for gd.chord), gd.noFill, and gd.edged. gd.arc and gd.chord are mutually exclusive; gd.chord just connects the starting and ending angles with a straight line, while gd.arc produces a rounded edge. gd.pie is a synonym for gd.arc. gd.noFill indicates that the arc or chord should be outlined, not filled. gd.edged, used together with gd.noFill, indicates that the beginning and ending angles should be connected to the center; this is a good way to outline (rather than fill) a 'pie slice'.

filledEllipse

filledEllipse(Center, 
              Size, 
              ColourIndex)
 
Name Type Default Description
Center Object An object with an x and y property
Size Object An object with a width and height property
ColourIndex Integer The index of an allocated color. See colorAllocate
filledEllipse(X, 
              Y, 
              Width, 
              Height, 
              ColourIndex)
 
Name Type Default Description
X Integer
Y Integer
Width Integer
Height Integer
ColourIndex Integer The index of an allocated color. See colorAllocate

filledEllipse is used to draw an ellipse centered at the given point, with the specified width and height in pixels. The ellipse is filled in the color specified by the last argument.

filledPolygon

filledPolygon(Points, 
              ColourIndex)
 
Name Type Default Description
Points Array An array with objects that have an x and y property
ColourIndex Integer The index of an allocated color. See colorAllocate

filledPolygon is used to fill a polygon with the verticies (at least 3) specified, using the color index specified.

filledRectangle

filledRectangle(Rect, 
                ColourIndex)
 
Name Type Default Description
Rect Object An object with a x, y, width and height property (like wxRect for example)
ColourIndex Integer The index of an allocated color. See colorAllocate
filledRectangle(X1, 
                Y1, 
                X2, 
                Y2, 
                ColourIndex)
 
Name Type Default Description
X1 Integer
Y1 Integer
X2 Integer
Y2 Integer
ColourIndex Integer The index of an allocated color. See colorAllocate

filledRectangle is used to draw a solid rectangle with the two corners (upper left first, then lower right) specified, using the color index specified.

getPixel

getPixel(point) : Integer
 
Name Type Default Description
point Object An object with an x and y property
getPixel(X, 
         Y) : Integer
 
Name Type Default Description
X Integer
Y Integer

getPixel retrieves the color index of a particular pixel.

green

green(C)
 
Name Type Default Description
C Integer

Returns the green portion of the specified color in the image.

line

line(From, 
     To, 
     ColourIndex)
 
Name Type Default Description
From Object An object with an x and y property
To Object An object with an x and y property
ColourIndex Integer The index of an allocated color. See colorAllocate
line(X1, 
     Y1, 
     X2, 
     Y2, 
     ColourIndex)
 
Name Type Default Description
X1 Integer
Y1 Integer
X2 Integer
Y2 Integer
ColourIndex Integer The index of an allocated color. See colorAllocate

line is used to draw a line between two endpoints (X1,Y1 and X2, Y2). The line is drawn using the color index specified. Note that the color index can be an actual color returned by colorAllocate or one of gd.Styled, gd.Brushed or gd.StyledBrushed.

openPolygon

openPolygon(Points, 
            ColourIndex)
 
Name Type Default Description
Points Array An array with objects that have an x and y property.
ColourIndex Integer The index of an allocated color. See colorAllocate

openPolygon is used to draw a polygon with the verticies (at least 3) specified, using the color index specified. Unlike poligon the enpoints of the line sequence are not connected to a closed polygon

paletteCopy

paletteCopy(Source)
 
Name Type Default Description
Source Image

Copies a palette from one image to this image, attempting to match the colors in this image to the colors in the source palette.

polygon

polygon(Points, 
        ColourIndex)
 
Name Type Default Description
Points Array An array with objects that have an x and y property
ColourIndex Integer The index of an allocated color. See colorAllocate

polygon is used to draw a polygon with the verticies (at least 3) specified, using the color index specified.

rectangle

rectangle(Rect, 
          ColourIndex)
 
Name Type Default Description
Rect Object An object with a x, y, width and height property
ColourIndex Integer The index of an allocated color. See colorAllocate
rectangle(X1, 
          Y1, 
          X2, 
          Y2, 
          ColourIndex)
 
Name Type Default Description
X1 Integer
Y1 Integer
X2 Integer
Y2 Integer
ColourIndex Integer The index of an allocated color. See colorAllocate

rectangle is used to draw a rectangle using the color index specified.

red

red(C)
 
Name Type Default Description
C Integer

Returns the red portion of the specified color in the image.

saveAlpha

saveAlpha(Switch)
 
Name Type Default Description
Switch Integer

setAntiAliased

setAntiAliased(ColourIndex)
 
Name Type Default Description
ColourIndex Integer The index of an allocated color. See colorAllocate

"Antialiasing" is a process by which jagged edges associated with line drawing can be reduced by blending the foreground color with an appropriate percentage of the background, depending on how much of the pixel in question is actually within the boundaries of the line being drawn. All line-drawing functions, such as line, openPolygon and polygon, will draw antialiased lines if the special "color" gd.AntiAliased is used when calling them.

setAntiAliased is used to specify the actual foreground color to be used when drawing antialiased lines.

Antialiased lines can be drawn on both truecolor and palette-based images. However, attempts to draw antialiased lines on highly complex palette-based backgrounds may not give satisfactory results, due to the limited number of colors available in the palette. Antialiased line-drawing on simple backgrounds should work well with palette-based images; otherwise create or fetch a truecolor image instead.

setAntiAliasedDontBlend

setAntiAliasedDontBlend(ColourIndex, 
                        DontBlend)
 
Name Type Default Description
ColourIndex Integer The index of an allocated color. See colorAllocate
DontBlend Integer

Normally, when drawing lines with the special gd.AntiAliased "color," blending with the background to reduce jagged edges is the desired behavior. However, when it is desired that lines not be blended with one particular color when it is encountered in the background, the setAntiAliasedDontBlend function can be used to indicate the special color that the foreground should stand out more clearly against.

setBrush

setBrush(Brush)
 
Name Type Default Description
Brush gd.Image A "brush" is an image used to draw wide, shaped strokes in another image

Just as a paintbrush is not a single point, a brush image need not be a single pixel. Any gd image can be used as a brush, and by setting the transparent color index of the brush image with colorTransparent, a brush of any shape can be created. All line-drawing functions, such as line, openPolygon and polygon, will use the current brush if the special "color" gd.Brushed or gd.StyledBrushed is used when calling them.

setBrush is used to specify the brush to be used in a particular image. You can set any image to be the brush. If the brush image does not have the same color map as the first image, any colors missing from the first image will be allocated. If not enough colors can be allocated, the closest colors already available will be used. This allows arbitrary PNGs to be used as brush images. It also means, however, that you should not set a brush unless you will actually use it; if you set a rapid succession of different brush images, you can quickly fill your color map, and the results will not be optimal.

setPixel

setPixel(Object, 
         ColourIndex)
 
Name Type Default Description
Object wxPoint An object with a x and y property
ColourIndex Integer The index of an allocated color. See colorAllocate
setPixel(X, 
         Y, 
         ColourIndex)
 
Name Type Default Description
X Integer
Y Integer
ColourIndex Integer The index of an allocated color. See colorAllocate

Sets a pixel to a particular color.

setStyle

setStyle(Style)
 
Name Type Default Description
Style Array An array of integers with the desired series of color values to be repeated. You can assign the special color value gd.Transparent to indicate that the existing color should be left unchanged for that particular pixel (allowing a dashed line to be attractively drawn over an existing image).

It is often desirable to draw dashed lines, dotted lines, and other variations on a broken line. setStyle can be used to set any desired series of colors, including a special color that leaves the background intact, to be repeated during the drawing of a line.

To draw a line using the style, use the normal line function with the special color value gd.Styled.

setThickness

setThickness(thickness)
 
Name Type Default Description
thickness Integer

Sets the width of lines drawn by the gd.Image#line, gd.Image#polygon, gd.Image#openPolygon and related functions, in pixels.

setTile

setTile(Tile)
 
Name Type Default Description
Tile gd.Image A "tile" is an image used to fill an area with a repeated pattern.

Any gd image can be used as a tile, and by setting the transparent color index of the tile image with colorTransparent, a tile that allows certain parts of the underlying area to shine through can be created. All region-filling functions, such as fill and filledPolygon, will use the current tile if the special "color" gd.Tiled is used when calling them.

sharpen

sharpen(Pct)
 
Name Type Default Description
Pct Integer

Sharpens the specified image. Pct is a sharpening percentage, and can be greater than 100. Silently does nothing to non-truecolor images. Silently does nothing for Pct < 0. Transparency/alpha channel are not altered.

squareToCircle

squareToCircle(Radius)
 
Name Type Default Description
Radius Integer

The image MUST be square, but can have any size. Creates a new image of width and height radius * 2, in which the X axis of the original has been remapped to theta (angle) and the Y axis of the original has been remapped to rho (distance from center). This is known as a "polar coordinate transform." See also stringFTCircle, which uses this function internally.

string

string(Font, 
       Point, 
       Str, 
       Colour)
 
Name Type Default Description
Font Font
Point Object An object with an x and y property
Str String
Colour Integer
string(Font, 
       X, 
       Y, 
       Str, 
       Colour)
 
Name Type Default Description
Font Font
X Integer
Y Integer
Str String
Colour Integer

string is used to draw a string on the image.

stringFT

stringFT(Fg, 
         FontName, 
         PointSize, 
         Angle, 
         Point, 
         Text) : Array
 
Name Type Default Description
Fg Integer
FontName String
PointSize Double
Angle Double
Point Object An object with x and y properties
Text String
stringFT(Fg, 
         FontName, 
         PointSize, 
         Angle, 
         X, 
         Y, 
         Text) : Array
 
Name Type Default Description
Fg Integer
FontName String
PointSize Double
Angle Double
X Integer
Y Integer
Text String

stringFT draws a string of anti-aliased characters on the image using the FreeType library to render user-supplied TrueType fonts. We do not provide TrueType fonts (.ttf and .ttc files). Obtaining them is entirely up to you. The string is anti-aliased, meaning that there should be fewer "jaggies" visible. The fontname is the full pathname to a TrueType font file, or a font face name if the GDFONTPATH environment variable has been set. In the absence of a full path, the font face name may be presented with or without extension.

The string may be arbitrarily scaled (ptsize) and rotated (angle in radians). The direction of rotation is counter-clockwise, with 0 radians (0 degrees) at 3 o'clock and PI/2 radians (90 degrees) at 12 o'clock.

This method returns an array with 2 elements: one with a possible error message and one with another array containing the bounding rectangle (the smallest rectangle that completely surrounds the rendered string and does not intersect any pixel of the rendered string). This array contains the following elements: 0 lower left corner, X position
1 lower left corner, Y position
2 lower right corner, X position
3 lower right corner, Y position
4 upper right corner, X position
5 upper right corner, Y position
6 upper left corner, X position
7 upper left corner, Y position


The points are relative to the text regardless of the angle, so "upper left" means in the top left-hand corner seeing the text horizontally.

Use gd.stringFT to get the bounding rectangle without rendering. This is a relatively cheap operation if followed by a rendering of the same string, because of the caching of the partial rendering during bounding rectangle calculation.

The string is rendered in the color indicated by the Fg color index. Use the negative of the desired color index to disable anti-aliasing.

An example:


    var err, rect;
    var font = "C:\\WINDOWS\\Fonts\\Times.ttf";
    [err, rect] = gd.stringFT(0, font, 40, 0, 0, 0, "Hello.");
    var img = new gd.Image(rect[2] - rect[6] + 6, 
                           rect[3] - rect[7] + 6);
    
    var white = img.colorResolve(0, 0, 0);
    var black = img.colorResolve(255, 255, 255);
    
    var x = 3 - rect[6];
    var y = 3 - rect[7];
    print("x = ", x, "\n");
    print("y = ", y, "\n");
    [err, rect] = img.stringFT(black, font, 40, 0, x, y, "Hello.");
    print(err, "\n");
    
    var jpg = new gd.ImageJPEG(img);
    jpg.write("c:\\temp\\ttf.jpg");
   

stringFTCircle

stringFTCircle(Center, 
               Radius, 
               TextRadius, 
               FillPortion, 
               Font, 
               Points, 
               Top, 
               Bottom, 
               Fg) : String
 
Name Type Default Description
Center Object An object with x and y properties
Radius Double
TextRadius Double
FillPortion Double
Font String
Points Double
Top String
Bottom String
Fg Index
stringFTCircle(X, 
               Y, 
               Radius, 
               TextRadius, 
               FillPortion, 
               Font, 
               Points, 
               Top, 
               Bottom, 
               Fg) : String
 
Name Type Default Description
X Integer
Y Integer
Radius Double
TextRadius Double
FillPortion Double
Font String
Points Double
Top String
Bottom String
Fg Index

Draws the text strings specified by Top and Bottom on image, curved along the edge of a circle of radius Radius, with its center at Center. Top is written clockwise along the top; Bottom is written counterclockwise along the bottom. TextRadius determines the "height" of each character; if textRadius is 1/2 of Radius, characters extend halfway from the edge to the center. FillPortion varies from 0 to 1.0, with useful values from about 0.4 to 0.9, and determines how much of the 180 degrees of arc assigned to each section of text is actually occupied by text; 0.9 looks better than 1.0 which is rather crowded. Font is a freetype font; stringFT. Points is passed to the freetype engine and has an effect on hinting; although the size of the text is determined by Radius, TextRadius, and FillPortion, you should pass a point size that "hints" appropriately -- if you know the text will be large, pass a large point size such as 24.0 to get the best results. Fg can be any color, and may have an alpha component, do blending, etc.

stringUp

stringUp(Font, 
         Point, 
         Str, 
         Colour)
 
Name Type Default Description
Font Font
Point Object An object with an x and y property
Str String
Colour Integer
stringUp(Font, 
         X, 
         Y, 
         Str, 
         Colour)
 
Name Type Default Description
Font Font
X Integer
Y Integer
Str String
Colour Integer

stringUp is used to draw multiple characters on the image, rotated 90 degrees




Design downloaded from Zeroweb.org: Free website templates, layouts, and tools.