'
' Demonstration for the GD library
'
' (c) PvE, May 2010 - GPL
'-----------------------------------------------

' Include context
INCLUDE "gd.bac"

DECLARE black, white, red, blue TYPE int

' Create image
im = gdImageCreate(400, 300)

' Background color (first allocated)
white = gdImageColorAllocate(im, 255, 255, 255)

' Allocate more clors
black = gdImageColorAllocate(im, 0, 0, 0)
red = gdImageColorAllocate(im, 255, 0, 0)
blue = gdImageColorAllocate(im, 0, 0, 255)

' Inscribe an ellipse, a rectangle and some text in the image
gdImageArc(im, 200, 150, 350, 250, 0, 360, black)
gdImageRectangle(im, 75, 75, 200, 150, black)
gdImageString(im, gdFontGetMediumBold(), 10, 10, "Hello BaCon world!", black)

' Fill using some colors
gdImageFill(im, 100, 100, blue)
gdImageFill(im, 250, 150, red)

' Write JPEG using default quality
OPEN "gd-demo.jpg" FOR WRITING AS jpeg
gdImageJpeg(im, jpeg, -1)
CLOSE FILE jpeg

' Show image
PRINT "Show image in Firefox (Y/N)?";
key = GETKEY
PRINT

IF key EQ 89 OR key EQ 121 THEN
    SYSTEM "firefox -new-tab gd-demo.jpg"
ELSE
    PRINT "Use a JPEG viewer to view 'gd-demo.jpg'!"
END IF

' Destroy image
gdImageDestroy(im)