gdImageArc(imgHnd, cx, cy, width, height, start, end, color) |
|||||||||||||||||||||
gdImageArc draws 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. The following code draws an ellipse on the screen. ... inside a function ... | |||||||||||||||||||||
gdImageFill(imgHnd, x, y, color) |
|||||||||||||||||||||
This function changes the color of an area. The pixel at x, y and all congruent pixels of the same color will be set to the color specified by color. For a way of flooding a region defined by a specific border color rather than by its interior color, see gdImageFillToBorder. The fill color can be gdTiled, resulting in a tile fill using another image as the tile. However, the tile image cannot be transparent. If the image you wish to fill with has a transparent color index, call gdImageTransparent on the tile image and set the transparent color index to -1 to turn off its transparency. Note that gdImageFill is recursive. It is not the most naïve implementation possible, and the implementation is expected to improve, but there will always be degenerate cases in which the stack can become very deep. This can be a problem in MSDOS and MS Windows environments. (Of course, in a UNIX or NT environment with a proper stack, this is not a problem at all.) |
|||||||||||||||||||||
gdImageFilledRectangle(imgHnd, x1, y1, x2, y2, color) |
|||||||||||||||||||||
gdImageFilledRectangle() draws a solid rectangle with the upper left (x1,y1) and lower right corners (x2, y2) specified, in the specified color. ... inside a function ... | |||||||||||||||||||||
gdImageFilledPolygon(gdImageHnd, gdPointPtr points, int pointsTotal, int color) |
|||||||||||||||||||||
gdImageFilledPolygon() fills a polygon defined by the points specified by the variable points. The polygon must have at least three points. It will be filled with the color specified by index. See also gdImagePolygon. |
|||||||||||||||||||||
... inside a function ... imgHnd = gdImageCreate(100, 100); Background color (first allocated) */ /* Paint it in white */ | |||||||||||||||||||||
gdImageLine is used to draws a line between x1,y1 and x2, y2.The line is drawn using the color index specified. Note that color index can be a color returned by gdImageColorAllocate or one of gdStyled, gdBrushed or gdStyledBrushed. im = gdImageCreate(100, 100); | |||||||||||||||||||||
gdImagePolygon(gdImageHndl im, gdPointPtr points, int pointsTotal, int colorIndex) |
|||||||||||||||||||||
gdImagePolygon draws a polygon with the vertices specified by points, in the color specified by colorIndex. There must be at least three points. See also gdImageFilledPolygon. imgHnd = gdImageCreate(100, 100); | |||||||||||||||||||||
gdImageRectangle draws a rectangle with the upper left (x1, y1) then lower right (y1,y2) corners specified, using the color index specified. im = gdImageCreate(100, 100); | |||||||||||||||||||||
gdImageCopy(destImgHnd, srcimgHnd, dx, dy, sx, sy, width, height) |
|||||||||||||||||||||
gdImageCopy copies a rectangular portion of srcimgHnd to destimgHng. (For a way of stretching or shrinking the image in the process, see gdImageCopyResized.) The dx and dy arguments specifies the upper left hand corner point in the destination image to which the region will be copied. The sx and sy arguments specify the upper left corner of the region in the source image. width and height specify the width and height of the region. When you copy a region from one location in an image to another location in the same image, gdImageCopy 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. gdImageCopy 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 gdImageColorExact. If such a value is not found, gdImageCopy will attempt to allocate colors as needed using gdImageColorAllocate. If both of these methods fail, gdImageCopy will invoke gdImageColorClosest to find the color in the destination image which most closely approximates the color of the pixel being copied. The example above takes a small gif file, and creates a larger one with the smaller image tiled on the background. /* Load a small gif to tile the larger one with */ | |||||||||||||||||||||
gdImageCopyResized(destImg, srcImg, dX, dY, sX, sY, dW, dH, sW, sH) |
|||||||||||||||||||||
gdImageCopyResized copies a rectangular portion of srcImg to destImg. dx and dy are the coordinates the upper left hand corner of the area being copied, and sx and sy are the coordinates the upper left hand corner of the region where the image is beng copied. 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. sw and sh are the width and height of the source image, and dw and dh are the width and height of the destination image.(For a simpler version of this function which does not deal with resizing, see gdImageCopy). dw and dh do not have to be equal to sw and sh, allowing a region to be scaled during the copying process. When you copy a region from one location in an image to anotherlocation in the same image, gdImageCopy will perform asexpected unless the regions overlap, in which case the result isunpredictable. If this presents a problem, create a scratch image inwhich to keep intermediate results. Important note on copying between images: since images do not necessarily have the same color tables, pixels are not simply set to the same color index values to copy them. gdImageCopyResized will attempt to find an identical RGB value in the destination image foreach pixel in the copied portion of the source image by invoking gdImageColorExact. If such a value is not found, gdImageCopyResized will attempt to allocate colors as needed using gdImageColorAllocate. If both of these methods fail, gdImageCopyResized will invoke gdImageColorClosest to find the colorin the destination image which most closely approximates the colorof the pixel being copied. /* Load a small gif to expand in the larger one */ | |||||||||||||||||||||
gdImageCreate creates an image that is x by y pixels. The image must eventually be destroyed with gdImageDestroy(). im = gdImageCreate(64, 64); | |||||||||||||||||||||
gdImageCreateFromGd() opens the file filename, which must be saved in gd format.You can inspect the sx and sy members of the image to determine its size. The image must eventually be destroyed with gdImageDestroy(). gdImageHndl im; | |||||||||||||||||||||
gdImageCreateFromGif() loads the .gif file specified by filename for editing. It returns a handle to the file being opened, or NULL if it was unable to load the file (most likely because the file is corrupt or is not a valid .gif file). The image must eventually be destroyed with gdImageDestroy. fp = Clib.fopen("mygd.gd", "rb"); | |||||||||||||||||||||
gdImageCreateFromXbm() loads images from X bitmap format files. imgHnd = gdImageCreateFromXbm("myxbm.xbm"); | |||||||||||||||||||||
gdImageDestroy() frees the memory allocated for the image. You must destroy all images created during your scripting session. gdImageHndl im; | |||||||||||||||||||||
gdImageGd() saves the image specified by imgHnd as the file filename in GD format. GD format is used by this library to quickly open and close images. /* Create the image */ | |||||||||||||||||||||
gdImageGif() saves the image specified by imgHnd as the file filename in GIF format. /* Create the image */ | |||||||||||||||||||||
gdImageInterlace 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. Passing a non-zero value sets interlace to ON; a zero value turns it off. Note that only .gif images support interlace; if the file is saved in other formats this information will be lost. By default, images are not interlaced. Images loaded with gdImageGif() will have the interlace value set in the GIF file. /* ... Create or load the image... */ | |||||||||||||||||||||
gdImageBlue returns the blue component of the specified color index. Use this macro rather than accessing the image directly. |
|||||||||||||||||||||
gdImageBoundsSafe() returns true if the point x,y is within the bounds of the image specified by imgHnd; otherwise it returns false if it is not. This function is intended primarily for those who wish to add their own functions to the library; all of the functions in this document clip safely to the image. im = gdImageCreate(100, 100); | |||||||||||||||||||||
This function returns true if the image specified by imgHnd is interlaced, and false if it is not. The interlaced format only applies to .gif images. See gdImageInterlace for a means of interlacing images. |
|||||||||||||||||||||
gdImageGetPixel() retrieves the color index of the pixel at the coordinates x,y. |
|||||||||||||||||||||
This function returns the color index of the trasparent color in the image specified by imgHnd, or -1 if there is no transparent color. |
|||||||||||||||||||||
gdImageGreen() returns the green component of the specified color index. Use this macro rather than accessing the image directly. |
|||||||||||||||||||||
gdImageRed() returns the red component of the specified color index. Use this macro rather than accessing the image directly. |
|||||||||||||||||||||
gdImageSX() returns the width of the image of the specified specified by imgHnd. Use this macro rather than accessing the image directly. |
|||||||||||||||||||||
gdImageSY() returns the height of the image of the specified specified by imgHnd. Use this macro rather than accessing the image directly. |
|||||||||||||||||||||
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 gdImageColorTransparent, a brush of any shape can be created. All line-drawing functions, such as gdImageLine and gdImagePolygon, will use the current brush if the special "color" gdBrushed or gdStyledBrushed is used when calling them. 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 GIFs 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. You need not take any special action when you are finished with a brush. As for any other image, if you will not be using the brush image for any further purpose, you should call gdImageDestroy. You must not use the color gdBrushed if the current brush has been destroyed; you can of course set a new brush to replace it. im = gdImageCreate(100, 100); | |||||||||||||||||||||
This function sets the pixel at x,y to the color specified by colorIndex. im = gdImageCreate(100, 100); | |||||||||||||||||||||
gdImageSetStyle() lets you draw dashed lines, dotted lines, and other variations on a broken line. It sets any desired series of colors (including a special color that leaves the background intact) to serve as a template for drawing the line. var imgHnd; | |||||||||||||||||||||
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 gdImageColorTransparent, a tile that allows certain parts of the underlying area to shine through can be created. All region-filling functions, such as gdImageFill and gdImageFilledPolygon, will use the current tile if the special "color" gdTiled is used when calling them. You can set any image to be the tile. If the tile 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 GIFs to be used as tile images. It also means, however, that you should not set a tile unless you will actually use it; if you set a rapid succession of different tile images, you can quickly fill your color map, and the results will not be optimal. You need not take any special action when you are finished with a tile. As for any other image, if you will not be using the tile image for any further purpose, you should call gdImageDestroy. You must not use the color gdTiled if the current tile has been destroyed; you can of course set a new tile to replace it. im = gdImageCreate(100, 100); | |||||||||||||||||||||
gdImageString() writes the contents of string on the image specified by imgHnd. The string will be drawn from left to right in the color indicated by color starting at the point x,y. Pixels not set by a particular character retain their previous color. The second argument is a pointer to a font definition structure. Five fonts are provided with gd: gdFontTiny, gdFontSmall, gdFontMediumBold, gdFontLarge, and gdFontGiant. See gdImageStringUp for a way of drawing vertical text, and gdImageChar for drawing single characters. /* String to draw. */ | |||||||||||||||||||||
gdImageChar() writes the character c on the image specified by imgHnd. The character will be drawn in the color indicated by color starting at the point x,y. Pixels not set by a particular character retain their previous color. The second argument is a pointer to a font definition structure. Five fonts are provided with gd: gdFontTiny, gdFontSmall, gdFontMediumBold, gdFontLarge, and gdFontGiant. See gdImageCharUp for a way of drawing vertical text, and gdImageString for drawing multiple characters (strings). im = gdImageCreate(100, 100); | |||||||||||||||||||||
gdImageCharUp() writes the character c vertically on the image specified by imgHnd. The string will be drawn from left to right in the color indicated by color starting at the point x,y. Pixels not set by a particular character retain their previous color. The second argument is a pointer to a font definition structure. Five fonts are provided with gd: gdFontTiny, gdFontSmall, gdFontMediumBold, gdFontLarge, and gdFontGiant. See gdImageChar for a way of drawing horizontal text, and gdImageString() and gdImageStringUp() for drawing multiple characters (strings). |
|||||||||||||||||||||
gdImageString() writes the contents of string on the image specified by imgHnd. The string will be drawn from left to right in the color indicated by color starting at the point x,y. Pixels not set by a particular character retain their previous color. The second argument is a pointer to a font definition structure. Five fonts are provided with gd: gdFontTiny, gdFontSmall, gdFontMediumBold, gdFontLarge, and gdFontGiant. See gdImageStringUp for a way of drawing vertical text, and gdImageChar for drawing single characters. var imgHnd; | |||||||||||||||||||||
gdImageColorAllocate finds the first available color index in the image specified, sets its RGB values to those requested (255 is the maximum for each), and returns the index of the new color table entry. When creating a new image, the first time you invoke this function you are setting the background color for this image. r, g, and b are integers representing the red, green and blue components of the color being allocated. The index of the new color table entry. In the event that all gdMaxColors colors (256) have already been allocated, gdImageColorAllocate will return -1 to indicate failure. (This is not uncommon when working with existing GIF files that already use 256 colors.) Note that gdImageColorAllocate does not check for existing colors that match your request; see gdImageColorExact and gdImageColorClosest for ways to locate existing colors that approximate the color desired in situations where a new color is not available. im = gdImageCreate(100, 100); | |||||||||||||||||||||
gdImageColorClosest 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 Euclidean distance, which is used to determine the distance in three-dimensional color space between colors. It returns the index of the color with RGB values closest to those of the request. If no colors have yet been allocated in the image, gdImageColorClosest returns -1. This function is most useful for choosing a drawing color when an image already contains gdMaxColors (256) colors and no more can be allocated. (This is not uncommon when working with existing GIF files that already use many colors.) See gdImageColorExact for a method of locating exact matches only. /* Suppose photo.gif is an image with many colors. */ | |||||||||||||||||||||
gdImageColorDeallocate 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 gdImageColorAllocate 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 gdImageColorDeallocate are made consecutively, the lowest-numbered index among them will be reused by the next gdImageColorAllocate call. im = gdImageCreateFromGif("photo.gif"); | |||||||||||||||||||||
gdImageColorExact searches the colors which have been defined thus far in the image specified. It returns the index of the first color with RGB values that exactly match those of the request. If no allocated color matches the request precisely, gdImageColorExact returns -1. im = gdImageCreateFromGif("photo.gif"); | |||||||||||||||||||||
gdImageColorTransparent sets the transparent color index for the specified image to the specified index. To indicate that there should be no transparent color, invoke gdImageColorTransparent with a color index of -1. The color index used should be an index allocated by gdImageColorAllocate, 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, 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 transparency. im = gdImageCreateFromGif("photo.gif"); | |||||||||||||||||||||
This value may ve used in place of a color when invoking a line-drawing function such as gdImageLine or gdImageRectangle. When gdBrushed is used as the color, the brush image (set with gdImageSetBrush) is drawn in place of each pixel of the line (the brush is usually larger than one pixel, creating the effect of a wide paintbrush). See also gdStyledBrushed for a way to draw broken lines with a series of distinct copies of an image.() |
|||||||||||||||||||||
The length of a dash in a dashed line. Defined to be 4 for backwards compatibility with programs that use gdImageDashedLine. New programs should use gdImageSetStyle and call the standard gdImageLine function with the special "color" gdStyled or gdStyledBrushed. |
|||||||||||||||||||||
The constant 256. This is the maximum number of colors in a GIF file according to the GIF standard, and is also the maximum number of colors in a gd image. |
|||||||||||||||||||||
Used in place of a color when invoking a line-drawing function such as gdImageLine or gdImageRectangle. When gdStyled is used as the color, the colors of the pixels are drawn successively from the style that has been set with gdImageSetStyle. If the color of a pixel is equal to gdTransparent, that pixel is not altered. (This mechanism is completely unrelated to the "transparent color" of the image itself; see gdImageColorTransparent for that mechanism.) See also gdStyledBrushed. |
|||||||||||||||||||||
Used in place of a color when invoking a line-drawing function such as gdImageLine or gdImageRectangle. When gdStyledBrushed is used as the color, the brush image set with gdImageSetBrush is drawn at each pixel of the line, providing that the style set with gdImageSetStyle contains a nonzero value (OR gdTransparent, which does not equal zero but is supported for consistency) for the current pixel. (Pixels are drawn successively from the style as the line is drawn, returning to the beginning when the available pixels in the style are exhausted.) Note that this differs from the behavior of gdStyled, in which the values in the style are used as actual pixel colors, except for gdTransparent. |
|||||||||||||||||||||
Used in place of a normal color in gdImageFilledRectangle, gdImageFilledPolygon, gdImageFill, and gdImageFillToBorder. gdTiled selects a pixel from the tile image set with gdImageSetTile in such a way as to ensure that the filled area will be tiled with copies of the tile image. See the discussions of gdImageFill and gdImageFillToBorder for special restrictions regarding those functions. |
|||||||||||||||||||||
Used in place of a normal color in a style to be set with gdImageSetStyle. gdTransparent is not the transparent color index of the image; for that functionality please see gdImageColorTransparent. |