|
Online demo.
(Hit F5 to see a new 'randomized' GIF generated!)
Introduction
This wrapper was developed by Trevor Herselman. GD is copyright 2005 Boutell.com, Inc. GD was developed by Thomas Boutell.
Files:
- bgd.dll -- GD library binary, downloadable from here. N.B.: Not my work!!!
- GDLibrary.dll -- ActiveX wrapper DLL, developed in VB6 with full source code! Needs to be registered before use!
VB Source Code
- GDLibrary.vbp -- Visual Basic 6 project file.
- gdImage.cls -- Class module file.
- modGDLibrary.bas -- Standard VB module file, with VB function declarations of the bgb.dll functions.
- modAPI.bas -- Standard VB module file, declaration of some Windows API functions, e.g.
copyMemory.
ASP Examples
- DynamicGif.asp -- Dynamic GIF example.
- DynamicPng.asp -- Dynamic true color PNG example.
- LoadPng.asp -- Example of loading a PNG file.
What is GD Library?
Edited quote from www.boutell.com:
"GD is an open source code library for the dynamic creation of images by programmers. GD creates PNG, JPEG and GIF images, and is commonly used to generate charts, graphics, thumbnails, graphs, text and almost anything on the fly."
FAQ
Why another wrapper?
Actually, it's the first of its kind and the only wrapper available for ASP developers. GD comes standard (built-in) with PHP 4.3.x.
Why use GD?
GD is a very mature and stable project. It's unbelievably fast and easy to use! PHP developers can easily see the similarities and ASP developers will have a smoother transition to PHP by using similar code! Take advantage of tutorials written for PHP with only syntax differences!
Why use this wrapper?
An image can be created/loaded, drawn on, saved to file or sent to a browser in less than 5 lines of code! There are several advantages ASP developers have, such as being able to read/write directly to BLOB or Image types in SQL. This wrapper creates an ADODB.Stream (ADO 2.8) object for internal use and is fully available to the client (object.Stream) with all the features and functionality that the Stream object brings!
What can GD do?
- Create Palette/True color images
GetPixel, SetPixel
- Draw lines, rectangles, arcs
- Fill areas to borders
- Filled arcs, filled ellipses
- Write horizontal/vertical text
What else can the wrapper do?
Gradient fills (horizontal and vertical), load/save from/to a file, memory or database (using ADO 2.8 Stream object). Output dynamic image directly to client.
Current wrapper limitations?
To draw various fonts, GD uses FreeType library, I'm having problems with the function declarations. I have problems with the declaration of the variable length polygon drawing functions.
Example 1
Create a 500x500 PNG image and draw a blue rectangle.
PHP<?php
$im = imagecreate(500, 500);
$white = imagecolorallocate($im, 255, 255, 255);
$blue = imagecolorallocate($im, 0, 0, 255);
imagerectangle($im, 3, 15, 390, 440);
header('Content-Type: image/png');
imagepng($im);
?>
ASP (JavaScript)<%
var gdImage = Server.CreateObject("GDLibrary.gdImage");
gdImage.Create(500, 500);
gdImage.ColorAllocate(255, 255, 255);
var Blue = gdImage.ColorAllocate(0, 0, 255);
gdImage.Rectangle(3, 15, 390, 440, Blue);
Response.ContentType = "image/png";
Response.BinaryWrite(gdImage.ToPngStream().Read);
%>
Example 2
Create a 230x20 image and write "My first Program with GD".
PHP<?php
header ("Content-type: image/png");
$img_handle = ImageCreate (230, 20) or die ("Cannot Create image");
$back_color = ImageColorAllocate ($img_handle, 0, 10, 10);
$txt_color = ImageColorAllocate ($img_handle, 233, 114, 191);
ImageString ($img_handle, 31, 5, 5,
"My first Program with GD", $txt_color);
ImagePng ($img_handle);
?>
ASP (JavaScript)<%
Response.ContentType = "image/png";
var gdImage = Server.CreateObject("GDLibrary.gdImage");
gdImage.Create(230, 20);
gdImage.ColorAllocate(0, 10, 10);
var TextColor = gdImage.ColorAllocate(233, 114, 191);
gdImage.Chars(gdImage.FontGetLarge(), 5, 5,
"My first Program with GD", TextColor);
Response.BinaryWrite(gdImage.ToPngStream().Read);
%>
Example 3
Draw lines 10 pixels apart in a for loop.
PHP<?php
Header("Content-type: image/png");
$height = 300;
$width = 300;
$im = ImageCreate($width, $height);
$bck = ImageColorAllocate($im, 10,110,100);
$white = ImageColorAllocate($im, 255, 255, 255);
ImageLine($im, 0, 0, $width, $height, $white);
for($i=0;$i<=299;$i=$i+10) {
ImageLine($im, 0, $i, $width, $height, $white); }
ImagePNG($im);
?>
ASP (JavaScript)<%
Response.ContentType = "image/png";
var height = 300;
var width = 300;
var gdImage = Server.CreateObject("GDLibrary.gdImage");
gdImage.Create(width, height);
gdImage.ColorAllocate(10, 110, 100);
var white = gdImage.ColorAllocate(255, 255, 255);
gdImage.Line(0, 0, width, height, white);
for (var i = 0; i < width; i += 10)
gdImage.Line(0, i, width, height, white);
Response.BinaryWrite(gdImage.ToPngStream().Read);
%>
Example 4
Draw an ellipse (oval)
PHP<?php
Header("Content-type: image/png");
$height = 300;
$width = 300;
$im = ImageCreate($width, $height);
$bck = ImageColorAllocate($im, 10,110,100);
$white = ImageColorAllocate($im, 255, 255, 255);
imageellipse ($im, 150, 150, 100, 200, $white);
ImagePNG($im);
?>
ASP (JavaScript)<%
Response.ContentType = "image/png";
var height = 300;
var width = 300;
var gdImage = Server.CreateObject("GDLibrary.gdImage");
gdImage.Create(width, height);
gdImage.ColorAllocate(10, 110, 100);
var white = gdImage.ColorAllocate(255, 255, 255);
gdImage.Ellipse(150, 150, 100, 200, white);
Response.BinaryWrite(gdImage.ToPngStream().Read);
%>
Example 5
Load a PNG from file, if the file is not found, create a new image with the message "Image Not Found".
PHP<?
header ("Content-type: image/png");
$im = @ImageCreateFromPNG ("php.png");
if(!$im) {
$img_handle = ImageCreate (200, 20) or die ("Cannot Create image");
$back_color = ImageColorAllocate ($img_handle, 0, 0, 0);
$txt_color = ImageColorAllocate ($img_handle, 255, 255, 255);
ImageString ($img_handle, 10, 25, 5, "Image Not Found", $txt_color);
ImagePng ($img_handle); }
Else {
echo "Image is Found"; }
?>
ASP (JavaScript)<%
Response.ContentType = "image/png";
var gdImage = Server.CreateObject("GDLibrary.gdImage");
if (!gdImage.LoadFromFile(Server.MapPath("dynamicpng.png"))) {
gdImage.Create(200, 20);
gdImage.ColorAllocate(0, 0, 0);
var TextColor = gdImage.ColorAllocate(255, 255, 255);
gdImage.Chars(gdImage.FontGetMediumBold(), 25, 5,
"Image Not Found", TextColor);
Response.BinaryWrite(gdImage.ToPngStream().Read); }
else {
Response.Write("Image is Found"); }
%>
This wrapper was developed by Trevor Herselman. GD is copyright 2005 Boutell.com, Inc. GD was developed by Thomas Boutell.
| You must Sign In to use this message board. |
|
| | Msgs 1 to 17 of 17 (Total in Forum: 17) (Refresh) | FirstPrevNext |
|
|
 |
|
|
Hi! I just wonder how I use this to resize an image and if format is *.jpg how do I do it..?
|
| Sign In·View Thread·PermaLink | 1.40/5 (4 votes) |
|
|
|
 |
|
|
 |
|
|
Can anyone enlighten me about how to set up this wrapper on an ASP page? I think this tutorial assumes far too much of its readers' knowledge of setting up a gd library. I've been trying to search for useful info on the web for hours with no luck.
Let me tell you what I've been able to get done so far. I created an asp document and added in code codes above into the body. I put the document on the server and tried to access it. No go. I guess what I need to figure out is how to include the dll's to an ASP page.
I appreciate your help.
|
| Sign In·View Thread·PermaLink | 3.50/5 (2 votes) |
|
|
|
 |
|
|
This is a very usefull program. But i need a tip of how can i set another font , because the Spammers can bypass it.
thanks again
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
I downloaded the gdwrapper, and wrote some code to generate an image of a part on the fly. But I want to save the image as a file for later use, and I want to save the image file in my SQL Server Database. I've done it on PHP 4.4 gd, but the JScript throws me off on this one.
I looked for some documentation on this, but haven't found any yet. Here is what I have so far. This is my first time using JScript. I call the file 'RenderPart.asp', I have hard Coded the values on the example.
<%@language=jscript%>
<%
//Gather all the data needed to make the drawing //var TX = Request.QueryString("TX") * 3 //var TY = Request.QueryString("TY") * 3
//var AX = Request.QueryString("AX") * 3 //var AY = Request.QueryString("AY") * 3
//var BX = Request.QueryString("BX") * 3 //var BY = Request.QueryString("BY") * 3 //var BV = Request.QueryString("BV") * 3
//var CX = Request.QueryString("CX") * 3 //var CY = Request.QueryString("CY") * 3 //var JobNumber = Request.QueryString("JN") var TX = 120 var TY = 90 var AX = 18 var AY = 44.7868 var BX = 39.2132 var BY = 45.2132 var BV = 30 var CX = 80.7868 var CY = 24 var JobNumber = "CF1" // Write image/png header Response.ContentType = "image/png";
// Set 'dynamic' content to expire immediately (depends on situation) Response.Expires = -1000;
// Create variables var gdImage = Server.CreateObject("GDLibrary.gdImage");
// Create a new paleted image in memory ... or ... //gdImage.Create(250, 200); //Calculate the image size if it gets real big var CTX; var CTY; if(TX > 480) { CTX = TX + 50; } else { CTX = 480; } if(TY > 320 ) { CTY = TY + 40; } else { CTY = 320; } gdImage.Create(CTX, CTY);
// Add/Return RGB True Color values var White = gdImage.ColorAllocate(255, 255, 255); var Black = gdImage.ColorAllocate(0, 0, 0); var Red = gdImage.ColorAllocate(255, 0, 0); var Blue = gdImage.ColorAllocate(0, 0, 255); var Green = gdImage.ColorAllocate(0, 255, 0);
//Calculate TotalBox First, Then Draw it //gdImage.Rectangle(0, 0, TX, TY, Black); //Caluclate PartB, then Draw it //(sX, sY, fX, fY, color) gdImage.Line(0, 0, 0, BY, Red); //Verrical gdImage.Line(0, 0, BX, 0, Red); //Horzontal gdImage.Line(0, BY, AX, BY, Red); gdImage.Line(BX, 0, BX, CY, Red); gdImage.Line(AX, BY, BX, CY, Red); //Vortex //Calculate PartA Next, then draw it //(sX, sY, fX, fY, color) gdImage.Rectangle(0, BY, AX, AY+BY, Red);
//Calculate PartC, then Draw it //(sX, sY, fX, fY, color) gdImage.Rectangle(BX, 0, CX+BX, CY, Red);
// Label the Drawing now //gdImage.Chars(gdImage.FontGetMediumBold(), 75, 10, "Horizontal Y-Axis", Black); //gdImage.CharsUp(gdImage.FontGetMediumBold(), 460, 225, "Vertical X-Axis", Black);
//gdImage.Chars(gdImage.FontGetTiny(), AX / 4, (BY / 4), "Part B", Black); //gdImage.Chars(gdImage.FontGetTiny(), AX / 4, AY, "Part A", Black); //gdImage.Chars(gdImage.FontGetTiny(), (CX / 3) + BX, (BY / 4), "Part C", Black);
gdImage.Chars(gdImage.FontGetMediumBold(), 10, TY + 20, "Scale: 3 Pixels Per Inch", Black); gdImage.Chars(gdImage.FontGetSmall(), 10, TY + 35, "Job Number: " + JobNumber, Black);
// Before output, if we want a Palleted Png (256 color), run the next command! gdImage.TrueColorToPalette(false, 256); // For Gradients, Dithering will help but increase the file size!
// Return a Png data stream Response.BinaryWrite(gdImage.ToPngStream().Read);
gdImage = null; %>
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have some problems with gbd.dll.. I registered successfully GDLibrary.dll. I'm trying it ina web application, but at the first operation with GDLibrary i receive the following errror message:
GDLibrary (0x800A0035) File not found: bgd.dll
The bgd.dll file is in the same directory where the script is..
Any idea?
Enzo
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
Hi Dade, nice work, but I can tell you, you're not the first who coded such a wrapper I already programmed something similar one year ago. I'm using for my LT Diagram Builder (ASP version). http://www.lutanho.net/diagram/index.html?download.html[^] The wrapper is in the gdImage.dll which can also be used independently from the Diagram Builder. It is using VBScript language instead of JavaScript. I didn't implement all methods from the gd library, only what is really important, so the dll is quite small.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
I downloaded yours and tested it. The bonus of your component is that you don't need to distribute bgd.dll separately, and it's written in C/C++ with the gd functions linked, should be a bit more efficient overall! The disadvantage is you don't distribute the source-code and it's not as comprehensive as mine! Would you be willing to send me your source-code so I can extend and enhance it?
I would therefore re-classify my project as the first extensive wrapper with source-code!
Regards
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
Hi.,
Im currently working on ASP Captcha Project. I suppose you ppl know what captcha is.
Well., The ASP Samples you gave is JS based., I tried converting it to VBS Based and it gave an heck a lot of error.,
[ I elimiated the common ones like Math.Random() to Rnd()., removing ';' and Setting it ]
Finally i got an image using VBS., but only using HARD CODED VALUES LIKE gdImage.Line 0, 0, 100, 10, gdImage.ColorAllocate(255,255,255) and not as gdImage.Line 0, 0, I, J, white., etc., Which means., this cannot be run on loops.
The Error is get is Type Mismatch.,
What to do ??? Help me., 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi, I just simply download your files and try it out. But cannot compile the DLL and asp file cannot work too.
Do I need to do anything else?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
What version of Visual Basic are you using? I have compiled the code on 2 machines with WinXP, VB6 (I use SP6). The code remains untested on VB.NET! What is the message you receive?
You may have to change the version of ADO being used! To select/check your version, select 'References' under 'Project' from the VB6 menu. Then go down the list until you see 'Microsoft ActiveX Data Objects 2.x Library'. Unselect the version currently used and select YOUR most recent version from the list. You might have a different version of ADO than the one being used! You can download ADO 2.8 from Microsoft!
I don't have any other ideas, if this doesn't work, tell me what the error message is!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I'm glad someone has exposed the great GD library to asp programmers - it's a big missing chunk of functionality that php zealots are quick to pounce on when people ask "php or asp?".
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|