-Table of Contents -

  1. GIFs-on-the-Fly Functions
  2. Miscellaneous Functions
  3. How to check syntax with WebCLIPS programs

GIFs-on-the-Fly Functions

The supplied functions support GIF image manipulation from a WebCLIPS program. By utilizing the gd functions a developer can dynamically generate new images or modify existing images. For each function, please review the documentation link labelled gdDoc for information on how to use gd functions in a program. These functions work exactly as their 'C' counterparts with these exceptions :

  1. Passing and returning parameters may be slightly different. These are documented for each function call.
  2. Calls to gdImageDestroy are optional! WebCLIPS tracks all allocated images and destroys them when the program has finished running.
  3. File I/O (opening files, closing files etc.) for image allocating functions (like gdImageCreate) are handled by WebCLIPS.

Function Listing :

Image creation, destruction, loading and saving

gdImageCreate - Allocates new images. Returns an EXTERNAL-ADDRESS to an image in memory. If the function fails, NULL is returned.
gdDoc

Syntax
(gdImageCreate <integer-expression x-size> <integer-expression y-size>)

Example

CLIPS>(defrule CreateImage
=>
(bind ?pImage (gdImageCreate 120 120)) ;120 x 120 pixel image
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return)))
Back to Function List


gdImageCreateFromGif - Allocates new images from existing GIF files. Returns an EXTERNAL-ADDRESS to an image in memory. If the function fails, NULL is returned.
gdDoc

Syntax
(gdImageCreateFromGif <string-or-symbol-expression filename>)

Example

CLIPS>(defrule CreateImageFromExisting
=>
(bind ?pImage (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Set the background color (number 0) to transparent.
(gdImageColorTransparent ?pImage 0)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\trancaut.gif"))
Back to Function List


gdImageCreateFromGd - Allocates new images from existing gd format files. Returns an EXTERNAL-ADDRESS to an image in memory. If the function fails, NULL is returned.
gdDoc

Syntax
(gdImageCreateFromGd <string-or-symbol-expression filename>)

Example

CLIPS>(defrule CreateImageFromExistingGd
=>
(bind ?pImage (gdImageCreateFromGd "c:\\gallery\\images\\GIF\\caution.gd"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Set the background color (number 0) to transparent.
(gdImageColorTransparent ?pImage 0)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\trancaut.gif"))
Back to Function List


gdImageCreateFromXbm - Allocates new images from existing Xbm format files. Returns an EXTERNAL-ADDRESS to an image in memory. If the function fails, NULL is returned.
gdDoc

Syntax
(gdImageCreateFromXbm <string-or-symbol-expression filename>)

Example

CLIPS>(defrule CreateImageFromExistingXbm
=>
(bind ?pImage (gdImageCreateFromXbm "c:\\gallery\\images\\XBM\\caution.xbm"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Save the new file as GIF
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\caution.gif"))
Back to Function List


gdImageGif - Saves GIF files to disk. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax
(gdImageGif <string-or-symbol-expression filename>)

Example

CLIPS>(defrule SaveImage
=>
(bind ?pImage (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Set the background color (number 0) to transparent.
(gdImageColorTransparent ?pImage 0)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\trancaut.gif"))
Back to Function List


gdImageGd - Saves GIF files to disk in native Gd format. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax
(gdImageGd <string-or-symbol-expression filename>)

Example

CLIPS>(defrule SaveImageGd
=>
(bind ?pImage (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Set the background color (number 0) to transparent.
(gdImageColorTransparent ?pImage 0)
;Save the new file
(gdImageGd ?pImage "c:\\gallery\\images\\GIF\\trancaut.gd"))
Back to Function List


gdImageDestroy - Destroys allocated images -- OPTIONAL. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax
(gdImageDestroy <EXTERNAL-ADDRESS>)

Example

CLIPS>(defrule DestroyImage
=>
(bind ?pImage (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Set the background color (number 0) to transparent.
(gdImageColorTransparent ?pImage 0)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\trancaut.gif")
(gdImageDestroy ?pImage))
Back to Function List

Drawing, styling, brushing, tiling and filling functions

gdImageSetPixel - sets a pixel to a color. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageSetPixel <EXTERNAL-ADDRESS> <integer-expression x>
                        <integer-expression y>
                        <integer-expression color>)

Example

CLIPS>(defrule SetPixel
=>
(bind ?pImage (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Set the background color (number 0) to transparent.
(gdImageColorTransparent ?pImage 0)
(bind ?iColor (gdImageColorAllocate ?pImage 255 255 255))
;Put a white pixel in the center of the picture
(gdImageSetPixel (/ (gdImageSX) 2) (/ (gdImageSX) 2) ?iColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\trancaut.gif"))
Back to Function List


gdImageLine - Draws a line. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageLine <EXTERNAL-ADDRESS> <integer-expression from-x>
                    <integer-expression from-y>
                    <integer-expression to-x>
                    <integer-expression to-y>
                    <integer-expression color>)

Example

CLIPS>(defrule DrawLine
=>
(bind ?pImage (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Get Grey Color
(bind ?iColor (gdImageColorAllocate ?pImage 127 127 127))
;Draw the 'grey' line
(gdImageLine ?pImage 0 0 (gdImageSX) (gdImageSY) ?iColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\caut1.gif"))
Back to Function List


gdImagePolygon - Draws a polygon. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImagePolygon <EXTERNAL-ADDRESS> <multifield-expression points>
<integer-expression color>)
Note : The multifield is a listing of x,y pairs. There MUST be 3 pairs of points in the mutlfield. If there is not at least 3 pairs of points gdImagePolygon will return FALSE. Also, if there is an x coordinate without a matching y coordinate (i.e. the number of elements in the multifield is odd) gdImagePolygon will return FALSE.

Example

CLIPS>(defrule PaintTriangle
=>
(bind ?pImage (gdImageCreate 220 120))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Grey background
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(bind ?Points (create$ 110 10 50 110 170 110))
(gdImagePolygon ?pImage ?Points ?iRedColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\triangle.gif"))
Back to Function List


gdImageRectangle - Draws a rectangle. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageRectangle <EXTERNAL-ADDRESS> <integer-expression upper-left-x>
                        <integer-expression upper-left-y>
                        <integer-expression lower-right-x>
                        <integer-expression lower-right-y>
                        <integer-expression color>)

Example

CLIPS>(defrule DrawRect
=>
(bind ?pImage (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Get Grey Color
(bind ?iColor (gdImageColorAllocate ?pImage 127 127 127))
;Draw the 'grey' rectangle
(gdImageRectangle ?pImage 10 10 (- (gdImageSX) 10) (- (gdImageSY) 10) ?iColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\caut1.gif"))
Back to Function List


gdImageFilledPolygon - Draws a polygon filled with a color. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageFilledPolygon <EXTERNAL-ADDRESS> <multifield-expression points>
                            <integer-expression color>)
Note : The multifield is a listing of x,y pairs. There MUST be 3 pairs of points in the mutlfield. If there is not at least 3 pairs of points gdImageFilledPolygon will return FALSE. Also, if there is an x coordinate without a matching y coordinate (i.e. the number of elements in the multifield is odd) gdImageFilledPolygon will return FALSE.

Example

CLIPS>(defrule PaintTriangle
=>
(bind ?pImage (gdImageCreate 220 120))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Grey background
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(bind ?Points (create$ 110 10 50 110 170 110))
(gdImageFilledPolygon ?pImage ?Points ?iRedColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\triangle.gif"))
Back to Function List


gdImageFilledRectangle - Draws a rectangle filled with a color. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageFilledRectangle <EXTERNAL-ADDRESS> <integer-expression upper-left-x>
                                <integer-expression upper-left-y>
                                <integer-expression lower-right-x>
                                <integer-expression lower-right-y>
                                <integer-expression color>)

Example

CLIPS>(defrule PaintJapaneseFlag
=>
(bind ?pImage (gdImageCreate 220 120))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Grey background
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iWhiteColor (gdImageColorAllocate ?pImage 255 255 255))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(gdImageFilledRectangle ?pImage 10 10 210 110 ?iWhiteColor)
;Red circle
(gdImageArc ?pImage 110 60 75 75 0 360 ?iRedColor)
;Fill it with red
(gdImageFill 110 60 ?iRedColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\japflag.gif"))
Back to Function List


gdImageArc - Draws ellipses. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageArc <EXTERNAL-ADDRESS> <integer-expression center-x>
                    <integer-expression center-y>
                    <integer-expression width>
                    <integer-expression height>
                    <integer-expression starting-position-degree>
                    <integer-expression ending-position-degree>
                    <integer-expression color>)

Example

CLIPS>(defrule PaintJapaneseFlag
=>
(bind ?pImage (gdImageCreate 220 120))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Grey background
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iWhiteColor (gdImageColorAllocate ?pImage 255 255 255))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(gdImageFilledRectangle ?pImage 10 10 210 110 ?iWhiteColor)
;Red circle
(gdImageArc ?pImage 110 60 75 75 0 360 ?iRedColor)
;Fill it with red
(gdImageFill 110 60 ?iRedColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\japflag.gif"))
Back to Function List


gdImageFillToBorder - Flood fill a color in a region up to a border color. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageFillToBorder <EXTERNAL-ADDRESS> <integer-expression x>
                            <integer-expression y>
                            <integer-expression border-color>)
                            <integer-expression color>)

Example

CLIPS>(defrule PaintJapFlagGreenBorder
=>
(bind ?pImage (gdImageCreate 220 120))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Grey background
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iWhiteColor (gdImageColorAllocate ?pImage 255 255 255))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(bind ?iGreenColor (gdImageColorAllocate ?pImage 0 255 0))
(gdImageFilledRectangle ?pImage 10 10 210 110 ?iWhiteColor)
;Red circle
(gdImageArc ?pImage 110 60 75 75 0 360 ?iGreenColor)
;Fill it with red
(gdImageFillToBorder 110 60 ?iGreenColor ?iRedColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\japflag.gif"))
Back to Function List


gdImageFill - Flood fill a color in a region. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageFill <EXTERNAL-ADDRESS> <integer-expression x>
                    <integer-expression y>
                    <integer-expression color>)

Example

CLIPS>(defrule PaintJapaneseFlag
=>
(bind ?pImage (gdImageCreate 220 120))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Grey background
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iWhiteColor (gdImageColorAllocate ?pImage 255 255 255))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(gdImageFilledRectangle ?pImage 10 10 210 110 ?iWhiteColor)
;Red circle
(gdImageArc ?pImage 110 60 75 75 0 360 ?iRedColor)
;Fill it with red
(gdImageFill 110 60 ?iRedColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\japflag.gif"))
Back to Function List


gdImageSetBrush - Sets the current painting brush. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageSetBrush <EXTERNAL-ADDRESS dest> <EXTERNAL-ADDRESS src>)

Example

(defmodule MAIN (import WebCLIPSTemplates deftemplate ?ALL)
(import WebCLIPSTemplates defglobal ?ALL))

CLIPS>(defrule PaintBrush
=>
(bind ?pImage (gdImageCreate 100 100))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Open the brush GIF. For best results, portions of the
;	brush that should be transparent (ie, not part of the
;	brush shape) should have the transparent color index.
(bind ?pBrush (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\pattern.gif")
;Grey background
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iWhiteColor (gdImageColorAllocate ?pImage 255 255 255))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(gdImageSetBrush ?pImage ?pBrush)
;Draw a line with the brush
(gdImageLine ?pImage 0 0 99 99 ?*gdBrushed*)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\newpatrn.gif"))
Back to Function List


gdImageSetTile - Sets the current Tile pattern. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageSetTile <EXTERNAL-ADDRESS dest> <EXTERNAL-ADDRESS src>)

Example

(defmodule MAIN (import WebCLIPSTemplates deftemplate ?ALL)
(import WebCLIPSTemplates defglobal ?ALL))

CLIPS>(defrule PaintwithTile
=>
(bind ?pImage (gdImageCreate 100 100))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Open the brush GIF. For best results, portions of the
;	brush that should be transparent (ie, not part of the
;	brush shape) should have the transparent color index.
(bind ?pTile (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\pattern.gif")
;Grey background
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iWhiteColor (gdImageColorAllocate ?pImage 255 255 255))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(gdImageSetTile ?pImage ?pBrush)
;Fill an area using the tile
(gdImageFilledRectangle pImage 25 25 75 75 ?*gdTiled*)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\newpatrn.gif"))
Back to Function List


gdImageSetStyle - Sets the current Style pattern. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageSetStyle <EXTERNAL-ADDRESS> <multfield color-slots>)

Example

(defmodule MAIN (import WebCLIPSTemplates deftemplate ?ALL)
(import WebCLIPSTemplates defglobal ?ALL))

CLIPS>(defrule LinewithStyle
=>
(bind ?pImage (gdImageCreate 220 120))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Grey background
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(bind ?iGreenColor (gdImageColorAllocate ?pImage 0 255 0))
(bind ?iWhiteColor (gdImageColorAllocate ?pImage 255 255 255))
(bind ?Points (create$ 110 10 50 110 170 110))
(gdImageFilledPolygon ?pImage ?Points ?iRedColor)
;Draw a line with a Style
(bind ?Style (create$ ?iRedColor ?iGreenColor ?iWhiteColor ?*gdTransparent*))
(gdImageSetStyle ?pImage ?Style)
(gdImageLine 10 10 100 100 ?*gdStyle*)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\triangle.gif"))
Back to Function List

Query functions

gdImageRed - Returns the RED component of a color. Returns the value if successful, -1 otherwise.
gdDoc

Syntax

   (gdImageRed <EXTERNAL-ADDRESS> <integer-expression color-slot>)

Example : see the gdFile Dump Utility


gdImageGreen - Returns the GREEN component of a color. Returns the value if successful, -1 otherwise.
gdDoc

Syntax

   (gdImageGreen <EXTERNAL-ADDRESS> <integer-expression color-slot>)

Example : see the gdFile Dump Utility


gdImageBlue - Returns the BLUE component of a color. Returns the value if successful, -1 otherwise.
gdDoc

Syntax

   (gdImageBlue <EXTERNAL-ADDRESS> <integer-expression color-slot>)

Example : see the gdFile Dump Utility


gdImageBoundsSafe - determines is a point (x,y) falls within an image. Returns the value if successful, -1 otherwise.
gdDoc

If the point (x, y) is within the image, gdImageBoundsSafe returns a 1, other wise it returns a 0.

Syntax

   (gdImageBoundsSafe <EXTERNAL-ADDRESS> <integer-expression x>
                            <integer-expression y>)

Example

CLIPS>(defrule GetBounds
=>
(bind ?pImage (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Is (100, 100) within the image?
(printout t (gdImageBoundsSafe ?pImage 100 100) crlf))
Back to Function List


gdImageColorsTotal - Returns the number of colors allocated to an image. Returns the value if successful, -1 otherwise.
gdDoc

Syntax

   (gdImageColorsTotal <EXTERNAL-ADDRESS>)

Example : see the gdFile Dump Utility


gdImageGetPixel - determines which color-slot is occupying (x,y)
gdDoc

Syntax

   (gdImageGetPixel <EXTERNAL-ADDRESS> <integer-expression x>
                        <integer-expression y>)

Example

CLIPS>(defrule GetPixelColor
=>
(bind ?pImage (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Prints the color slot for pixel at (10,10)
(printout t (gdImageGetPixel ?pImage 10 10) crlf))
Back to Function List


gdImageGetTransparent - Returns the color slot of the transparent color. Returns the value if successful, -1 otherwise.
gdDoc

Syntax

   (gdImageGetTransparent <EXTERNAL-ADDRESS>)

Example : see the gdFile Dump Utility


gdImageGetInterlaced - Returns a 1 (TRUE) if the image is interlaced, 0 (FALSE) if not. Returns the value if successful, -1 otherwise.
gdDoc

Syntax

   (gdImageGetInterlaced <EXTERNAL-ADDRESS>)

Example : see the gdFile Dump Utility


gdImageSX - Returns the size of the image in the x-direction. Returns the value if successful, -1 otherwise.
gdDoc

Syntax

   (gdImageSX <EXTERNAL-ADDRESS>)

Example : see the gdFile Dump Utility


gdImageSY - Returns the size of the image in the y-direction. Returns the value if successful, -1 otherwise.
gdDoc

Syntax

   (gdImageSY <EXTERNAL-ADDRESS>)

Example : see the gdFile Dump Utility

gdFile Dump Utility

;;; (InGIFFile c:\Gallery\Images\GIF\computer.gif) -- for example
(defrule gdDisplay
(InGIFFile ?InFile)
=>
(bind ?ptrImage (gdImageCreateFromGif ?InFile))
(if (nullp ?ptrImage)
then
(printout t "Image could not be loaded")
(return))

(printout t "File Information for : " ?InFile crlf crlf)
(printout t "X Size : " (gdImageSX ?ptrImage) " Y Size : " (gdImageSY ?ptrImage) crlf)
(bind ?iTotColors (gdImageColorsTotal ?ptrImage))
(printout t "Total Number of Colors : " ?iTotColors crlf)
(if (= (gdImageGetInterlaced ?ptrImage) 0)
then
(printout t "Image Not Interlaced" crlf)
else
(printout t "Image Not Interlaced" crlf))

(bind ?iTrans (gdImageGetTransparent ?ptrImage))
(if (eq ?iTrans -1)
then
(printout t "No transparent color specified" crlf)
else
(printout t "Transparent color number is : " ?iTrans crlf))

;;;
;;; Display the color Table
;;;
(printout t "Color Number" Red Green Blue)
(loop-for-count (?Indx 1 ?iTotColors) do
(printout t  ?Indx " " (gdImageRed ?ptrImage ?Indx) " " (gdImageGreen ?ptrImage ?Indx) " " (gdImageBlue ?ptrImage ?Indx))))
Back to Function List

Font and text-handling functions


gdImageChar - Displays a character in an image. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageChar <EXTERNAL-ADDRESS> <string-or-symbol-expression font>
                    <integer-expression x>
                    <integer-expression y>
                    <string-or-symbol-expression c>
                    <integer-expression color>)
Note : The parameter font must be one of the following values (case insensitive) :
  1. giant
  2. large
  3. mediumbold
  4. small
  5. tiny
If any other value is passed, gdImageChar will return FALSE.

Example

CLIPS>(defrule PrintChar
=>
(bind ?pImage (gdImageCreate 100 100))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(gdImageChar ?pImage "tiny" 75 75 W ?iRedColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\LetterW.gif"))
Back to Function List


gdImageCharUp - Displays a character in an image vertically. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageCharUp <EXTERNAL-ADDRESS> <string-or-symbol-expression font>
                        <integer-expression x>
                        <integer-expression y>
                        <string-or-symbol-expression c>
                        <integer-expression color>)
Note : The parameter font must be one of the following values (case insensitive) :
  1. giant
  2. large
  3. mediumbold
  4. small
  5. tiny
If any other value is passed, gdImageCharUp will return FALSE.

Example

CLIPS>(defrule PrintCharUp
=>
(bind ?pImage (gdImageCreate 100 100))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(gdImageCharUp ?pImage "giant" 75 75 "i" ?iRedColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\LetterI.gif"))
Back to Function List


gdImageString - Displays a string in an image. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageString <EXTERNAL-ADDRESS> <string-or-symbol-expression font>
                        <integer-expression x>
                        <integer-expression y>
                        <string-or-symbol-expression string>
                        <integer-expression color>)
Note : The parameter font must be one of the following values (case insensitive) :
  1. giant
  2. large
  3. mediumbold
  4. small
  5. tiny
If any other value is passed, gdImageString will return FALSE.

Example

CLIPS>(defrule PrintString
=>
(bind ?pImage (gdImageCreate 100 100))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(gdImageString ?pImage "small" 10 40 "up the exchange" ?iRedColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\ute.gif"))
Back to Function List


gdImageStringUp - Displays a string in an image vertically. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageStringUp <EXTERNAL-ADDRESS> <string-or-symbol-expression font>
                        <integer-expression x>
                        <integer-expression y>
                        <string-or-symbol-expression string>
                        <integer-expression color>)
Note : The parameter font must be one of the following values (case insensitive) :
  1. giant
  2. large
  3. mediumbold
  4. small
  5. tiny
If any other value is passed, gdImageStringUp will return FALSE.

Example

CLIPS>(defrule PrintStringUp
=>
(bind ?pImage (gdImageCreate 100 100))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(gdImageStringUp ?pImage mediumbold 10 90 "hi there" ?iRedColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\ht.gif"))
Back to Function List

Color handling functions

gdImageColorAllocate - Allocates a color slot for an image. First color allocated is the background color. Returns the value if successful, -1 otherwise.
gdDoc

Syntax

   (gdImageColorAllocate <EXTERNAL-ADDRESS> <integer-expression red-value>
                            <integer-expression green-value>
                            <integer-expression blue-value>)

Example

CLIPS>(defrule PaintJapaneseFlag
=>
(bind ?pImage (gdImageCreate 220 120))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Grey background
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
(bind ?iWhiteColor (gdImageColorAllocate ?pImage 255 255 255))
(bind ?iRedColor (gdImageColorAllocate ?pImage 255 0 0))
(gdImageFilledRectangle ?pImage 10 10 210 110 ?iWhiteColor)
;Red circle
(gdImageArc ?pImage 110 60 75 75 0 360 ?iRedColor)
;Fill it with red
(gdImageFill 110 60 ?iRedColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\japflag.gif"))
Back to Function List


gdImageColorClosest - Allocates the closest color. Returns the value if successful, -1 otherwise.
gdDoc

Syntax

   (gdImageColorClosest <EXTERNAL-ADDRESS> <integer-expression red-value>
                            <integer-expression green-value>
                            <integer-expression blue-value>)

Example

CLIPS>(defrule GetClosestColor
=>
(bind ?pImage (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Get the closest color to grey
(bind ?iColor (gdImageColorClosest ?pImage 127 127 127))
(if (= ?iColor -1)
then
(printout t "Color Allocation failed" crlf)
(return))
;Draw the 'grey' line
(gdImageLine ?pImage 0 0 (gdImageSX) (gdImageSY) ?iColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\trancaut.gif"))
Back to Function List


gdImageColorExact - Allocates the exact color. Returns the value if successful, -1 otherwise.
gdDoc

Syntax

   (gdImageColorExact <EXTERNAL-ADDRESS> <integer-expression red-value>
                            <integer-expression green-value>
                            <integer-expression blue-value>)

Example

CLIPS>(defrule GetExactColor
=>
(bind ?pImage (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Get Grey Color
(bind ?iColor (gdImageColorExact ?pImage 127 127 127))
(if (= ?iColor -1) ;Try to get close to Grey
then
(bind ?iColor (gdImageColorClosest ?pImage 127 127 127)))
;Draw the 'grey' line
(gdImageLine ?pImage 0 0 (gdImageSX) (gdImageSY) ?iColor)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\trancaut.gif"))
Back to Function List


gdImageColorDeallocate - Releases a color slot for an image. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageColorDeallocate <EXTERNAL-ADDRESS> <integer-expression color-slot>)

Example

CLIPS>(defrule RemoveColor
=>
(bind ?pImage (gdImageCreate 220 120))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Grey background
(bind ?iBGColor (gdImageColorAllocate ?pImage 127 127 127))
;Slot 1 is assigned White
(bind ?iColor (gdImageColorAllocate ?pImage 255 255 255))
(gdImageColorDeallocate ?iColor)
;Slot 1 is now free
;Slot 1 will be assigned Green
(bind ?iColor (gdImageColorAllocate ?pImage 0 255 0)))
Back to Function List


gdImageColorTransparent - Dictates which color is transparent. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax
(gdImageColorTransparent <EXTERNAL-ADDRESS> <integer-expression color-slot>)

Example

CLIPS>(defrule TransparentGIF
=>
(bind ?pImage (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
;Set the background color (number 0) to transparent.
(gdImageColorTransparent ?pImage 0)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\trancaut.gif"))
Back to Function List

Copying and resizing functions

gdImageCopy - Copy a portion of one image to another. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageCopy <EXTERNAL-ADDRESS dst>
<EXTERNAL-ADDRESS src>
<integer-expression dst-x>
<integer-expression dst-y>
<integer-expression src-x>
<integer-expression src-y>
<integer-expression width>
<integer-expression height>)

Example

CLIPS>(defrule QuarterGIF
=>
(bind ?pSrc (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pSrc)
then
(printout t "Source Image could not be allocated" crlf)
(return))
(bind ?pDst (gdImageCreate (/ (gdImageSX ?pSrc) 2) (/ (gdImageSY ?pSrc) 2)))
(if (nullp ?pDst)
then
(printout t "Dest Image could not be allocated" crlf)
(return))
(gdImageCopy ?pDst ?pSrc 0 0 0 0 (/ (gdImageSX ?pSrc) 2) (/ (gdImageSY ?pSrc) 2))
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\cautquar.gif"))
Back to Function List

gdImageCopyResized - Copy a portion of one image to another. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageCopyResized <EXTERNAL-ADDRESS dst>
        <EXTERNAL-ADDRESS src>
        <integer-expression dst-x>
        <integer-expression dst-y>
        <integer-expression src-x>
        <integer-expression src-y>
        <integer-expression dst-width>
        <integer-expression dst-height>
        <integer-expression src-width>
        <integer-expression src-height>)

Example

CLIPS>(defrule ShrinkGIF
=>
(bind ?pSrc (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pSrc)
then
(printout t "Source Image could not be allocated" crlf)
(return))
(bind ?pDst (gdImageCreate (/ (gdImageSX ?pSrc) 2) (/ (gdImageSY ?pSrc) 2)))
(gdImageCopyResized ?pDst ?pSrc 0 0 0 0 (gdImageSX ?pDst) (gdImageSY ?pDst) (gdImageSX ?pSrc) (gdImageSY ?pSrc) )
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\cautsmal.gif"))
Back to Function List

Miscellaneous

gdImageInterlace - Makes an image interlaced or not. Returns TRUE if successful, FALSE otherwise.
gdDoc

Syntax

   (gdImageInterlace <EXTERNAL-ADDRESS dst>
        <integer-expression 1-or-0>)

Passing a non-zero value to gdImageInterlace turns interlacing ON; a zero value turns it OFF

Example

CLIPS>(defrule InterlaceGIF
=>
(bind ?pImage (gdImageCreateFromGif "c:\\gallery\\images\\GIF\\caution.gif"))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return))
(gdImageInterlace  ?pImage 1)
;Save the new file
(gdImageGif ?pImage "c:\\gallery\\images\\GIF\\cautintr.gif"))
Back to Function List

Constants

gdDoc

Given below is the list of 'constant' values (defglobals) used in manipulating GIF images. By including the following 2 lines of code into a WebCLIPS program, these values will be defined :

(defmodule MAIN (import WebCLIPSTemplates deftemplate ?ALL)
(import WebCLIPSTemplates defglobal ?ALL))
Back to Function List

Go to Table of Contents


Miscellaneous Functions This is a collection of miscellaneous useful functions.

Function Listing :

  1. nullp
  2. gen-filename
  3. getenv
  4. putenv
  5. qsort


nullp
The nullp function takes an <EXTERNAL-ADDRESS> as it argument and returns TRUE if it is NULL, FALSE otherwise.

Syntax
(nullp <expression>)

Example

CLIPS>(defrule CreateImage
=>
(bind ?pImage (gdImageCreate 120 120))
(if (nullp ?pImage)
then
(printout t "Image could not be created" crlf)
(return)
else
(printout t ?pImage)))

<Pointer-011B0098>


gen-filename
The gen-filename function returns a string that is a unique filename in the directory contained in the TMP environment variable. TMP will be set to the [System] CLIPSOutput entry in WebCLIPS.INI. The filename has a prefix of WC.
The function has one input parameter which is the extension of the filename.

Syntax
(gen-filename <expression>)

Example

CLIPS>(defrule GetFileName
=>
(bind ?strFile (gen-filename "GIF"))
(printout t ?strFile crlf))

c:\windows\temp\wc2.gif


getenv
The getenv function works similiarly to the C function. It takes a string as it's only input parameter and returns a string that is the value of that environment variable.

Example

CLIPS>(defrule GetPath
=>
(printout t (getenv "PATH"))

c:\windows\command;c:\;c:\windows\system


putenv
The putenv function works similiarly to the C function. It takes a string as it's only input parameter and returns TRUE if successful, FALSE otherwise. This is another method for squirreling away string variables that will be easily accessible throughout the program.

Example

CLIPS>(defrule Valve6closed
(valve (num 6) (status closed))
=>
(printout t (putenv "v6=closed"))

TRUE


qsort
The qsort function accepts a multifield of INTEGERs, FLOATs, SYMBOLs or STRINGs and returns a multifield sorted using the quicksort algorithm.

Note : ALL elements of the multifield MUST be the same data type. It will be assumed that the data type of the first element is the data type for ALL elements in the multifield. If a multifield with mixed data types is submitted to qsort UNPREDICTABLE results will occur.

SYMBOLs and STRINGs may be mixed in a single multifield.

Example 1

CLIPS>(defrule SortInts
=>
(bind ?UnsortedInts (create$ 885 24 55 95 5432 4 69 -45))
(bind ?SortedInts (qsort ?UnsrtedInts))
(printout t "Original array : " ?UnsortedInts " Sorted Array " ?SortedInts crlf))

Original array : (885 24 55 95 5432 4 69 -45) Sorted Array (-45 4 24 55 69 95 885 5432)

Example 2

CLIPS>(defrule SortSymsStrings
=>
(bind ?Saying (create$ "the" spirit "is" willing "but" the "flesh" is "weak"))
(bind ?SortedSaying (qsort ?Saying))
(printout t "Original Array : " ?Saying crlf "Sorted Array : " ?SortedSaying crlf))

Original Array : ("the" spirit "is" willing "but" the "flesh" is "weak")
Sorted Array : (but flesh is is spirit the the weak willing)

Go to Table of Contents


How to check syntax with WebCLIPS programs

The WebCLIPS IDE can be used to check the syntax of User-Defined functions.

You can also use the utility provided as part of WebCLIPS.

  1. Copy ufsyntax.exe into the 'cgi-bin' directory of your web server.

  2. Copy ufsyntax.htm into the root directory of your web server.

  3. Bring up ufsyntax.htm in your web browser.

  4. Fill in the name of the program.

  5. If you would like the WebCLIPS helper files loaded, then click the checkbox. Information regarding WebCLIPS Helper Functions and Admin information are available.

  6. Click the button labelled Check Syntax .

Go to Table of Contents


gd 1.2 is copyright 1994, 1995, Quest Protein Database Center, Cold Spring Harbor Labs. Permission granted to copy and distribute this work provided that this notice remains intact. Credit for the library must be given to the Quest Protein Database Center, Cold Spring Harbor Labs, in all derived works. This does not affect your ownership of the derived work itself, and the intent is to assure proper credit for Quest, not to interfere with your use of gd. If you have questions, ask. ("Derived works" includes all programs that utilize the library. Credit must be given in user-visible documentation.)

Written by Thomas Boutell , 2/94 - 7/95.

The GIF compression code is based on that found in the pbmplus utilities, which in turn is based on GIFENCOD by David Rowley. See the notice below:

/*
** Based on GIFENCOD by David Rowley .A
** Lempel-Zim compression based on "compress".
**
** Modified by Marcel Wijkstra 
**
** Copyright (C) 1989 by Jef Poskanzer.
**
** Permission to use, copy, modify, and distribute this software and its
** documentation for any purpose and without fee is hereby granted, provided
** that the above copyright notice appear in all copies and that both that
** copyright notice and this permission notice appear in supporting
** documentation.  This software is provided "as is" without express or
** implied warranty.
**
** The Graphics Interchange Format(c) is the Copyright property of
** CompuServe Incorporated.  GIF(sm) is a Service Mark property of
** CompuServe Incorporated.
*/

The GIF decompression is based on that found in the pbmplus utilities, which in turn is based on GIFDECOD by David Koblas. See the notice below:

/* +-------------------------------------------------------------------+ */
/* | Copyright 1990, 1991, 1993, David Koblas.  (koblas@netcom.com)    | */
/* |   Permission to use, copy, modify, and distribute this software   | */
/* |   and its documentation for any purpose and without fee is hereby | */
/* |   granted, provided that the above copyright notice appear in all | */
/* |   copies and that both that copyright notice and this permission  | */
/* |   notice appear in supporting documentation.  This software is    | */
/* |   provided "as is" without express or implied warranty.           | */
/* +-------------------------------------------------------------------+ */

Go to Table of Contents


Last modified : 27-Jan-1998
Michael Giordano