<[ 

//*********************************************************************************************************************************
// Example of GD with GDLibrary.dll wrapper.

// Edited quote from boutell.com:
// GD is an open source code library for the dynamic creation of images. GD creates PNG, JPEG and GIF images, among other formats. 
// GD is commonly used to generate charts, graphics, thumbnails, and most anything else, on the fly. While not restricted to use 
// on the web, the most common applications of GD involve web site development. 

// Requirements
// bgd.dll - GD library binary, have to be located in the same folder with engine.exe.
// GDLibrary.dll - ActiveX wrapper DLL, needs to be registered with regsvr32 before use

// GDLibrary wrapper was developed by Trevor Herselman. GD is copyright 2005 Boutell.com, Inc. GD was developed by Thomas Boutell.

//*********************************************************************************************************************************

class gdPoint
    local x
    local y
end

function random( number )
    return( rand() % number )
end

session = new ( "session" )
session.mimeType = ".gif"
  
// register COM object
gdImage = new ( "com", "GDLibrary.gdImage" )


// Create a new paleted image in memory ... or ...
//gdImage.Create(250, 200)

// Because we're gonna draw a gradient, we create a True Color image!
// GD Library will dither and convert it to a Palette on output!
gdImage.CreateTrueColor(250, 200)

// Load background image from file
if ( ! gdImage.LoadFromFile("C:\MyDocuments\Imaging Dll\GDLibraryWrapper\starbg-1.jpg") )
    session.response ( "Unable to load image!" )
end

// Add/Return Colors to Palette
Black = gdImage.ColorAllocate(0, 0, 0) // First color added will always be background color. Palette Index = 0
Red = gdImage.ColorAllocate(255, 0, 0) // Palette Index = 1
Green = gdImage.ColorAllocate(0, 255, 0) // Palette Index = 2
Blue = gdImage.ColorAllocate(0, 0, 255) // Palette Index = 3 (Image is now 4 color)
Yellow = gdImage.ColorAllocate(255, 255, 0) // Image becomes 8 color
Magenta = gdImage.ColorAllocate(255, 0, 255)
// RandomColor1 = gdImage.ColorAllocate(random() * 255, random() * 255, random() * 255)
// RandomColor2 = gdImage.ColorAllocate(random() * 255, random() * 255, random() * 255)

// Drawing 3 Squares
gdImage.Rectangle(0, 0, 5, 5, Red)
gdImage.Rectangle(10, 10, 15, 15, Green)
gdImage.Rectangle(20, 20, 25, 25, Blue)

// Draw 300 Random Pixels
for (i = 0; i < 100; i++)
    gdImage.SetPixel(random(100), random(100), Red)
    gdImage.SetPixel(random(100), random(100), Green)
    gdImage.SetPixel(random(100), random(100), Blue)
end

// Draw Arc
gdImage.Arc(200, 100, 50, 50, 90, 180, Blue)
// Draw Circle
gdImage.Arc(50, 150, 50, 50, 0, 360, Red)

// Fill the Circle (With a different color)
gdImage.Fill(50, 150, Green)

// Draw Filled Arc (Can be used for Pie Charts etc.)
gdImage.FilledArc(150, 150, 50, 50, 0, 270, Red, 2)

// Draw an Oval (Ellipse)!
gdImage.FilledEllipse(125, 100, 30, 20, Yellow)

// Draw 5 Random Lines - With Random Color! (Color gets added to the palette!)
for (i = 0; i < 5; i++)
    gdImage.Line(random(200), random(200), random(200), random(200), gdImage.ColorAllocate(random(255) , random(255), random(255)) )
end

// Draw random Gradient!
gdImage.GradientFillRect(gdImage.ColorAllocate(random(255), random(255), random(255)), gdImage.ColorAllocate(random(255), random(255), random(255)), 50, 5, 245, 25, 0)
gdImage.GradientFillRect(gdImage.ColorAllocate(random(255), random(255), random(255)), gdImage.ColorAllocate(random(255), random(255), random(255)), 225, 40, 245, 195, 1)

// Draw Text
tmp = random(50)
gdImage.Chars(gdImage.FontGetMediumBold(), (tmp + 75), 10, "Horizontal Gradient", Red)
gdImage.CharsUp(gdImage.FontGetMediumBold(), 230, 190, "Vertical Gradient", Blue)

gdImage.Chars(gdImage.FontGetMediumBold(), 25, 35, "Random", Red)
gdImage.Chars(gdImage.FontGetMediumBold(), 25, 45, "Pixels", Red)

gdImage.Chars(gdImage.FontGetMediumBold(), 185, 100, "Arc", Blue)
gdImage.Chars(gdImage.FontGetMediumBold(), 155, 130, "Pie", Red)
gdImage.Chars(gdImage.FontGetMediumBold(), 105, 75, "Elipse", Yellow)

gdImage.Chars(gdImage.FontGetTiny(), 35, 140, "Fill to", Black)
gdImage.Chars(gdImage.FontGetTiny(), 37, 150, "border", Black)

gdImage.Chars(gdImage.FontGetMediumBold(), 30, 110, "Circle", Red)

gdImage.Chars(gdImage.FontGetTiny(), 50, 185, "GD library in FGL example", Green)

// Before output, if we don't want a dithered Gif, run the following command!
//gdImage.TrueColorToPalette(0, 256)
// For Gradients, Dithering will help but increase the file size!

// Return a Jpg data stream
// Output the image to the browser.
session.response ( gdImage.ToJpegStream().Read ( -1 ) )
 
return  

// fglSourceLink( "copyright")

 
]>

Click here to view the FGL source code for this page...
http://www.fifthgensys.com
View Source