DynImage Documentation
by Chris Ashton
June 2002
version 1.03
This ActiveX object enables ASP developers to create on-the-fly dynamic images for their
website in PNG (Portable Network Graphics) format. I developed it for myself for one
of my side projects, being unable to find a similar piece of software that did what
I wanted and that WASN'T extortionately priced. Although probably obsoleted by ASP.Net,
I still release it to the world at large, free of charge. Share and enjoy.
DynImage was created using libpng,
which rocks, Microsoft Visual C++ 6.0, which somewhat rocks, and ATL, which most emphatically
does not rock.
[New: Jan 29, 2003] -- some users reported that, on Windows 98, regsvr32 fails with
the error message "DllRegisterServer in dynimage.dll failed. Return code was: 0x80070078".
The problem was that earlier of DynImage and earlier were built for Unicode systems (NT, 2000, XP).
This has now been fixed in version 1.03, which uses one-byte-char functions and should run on all
systems.
Let me know if you encounter any problems with this
control, and I'll get right to fixing it.
How To Use
To install, copy the DLL file dynimage.dll (111K) to your server
and then run "regsvr32 dynimage.dll" from the command line. You're now ready to go!
In your ASP page, use the following code as a start:
Dim oDynImage
Set oDynImage = CreateObject("DynImage.DynImage")
oDynImage.Open 300, 300
oDynImage.Color = &hFF0000
oDynImage.Line 100, 100, 200, 200
Response.ContentType = "image/png"
Response.BinaryWrite oDynImage.Image
oDynImage.Close
Or, if you prefer JScript:
var oDynImage;
oDynImage = new ActiveXObject("DynImage.DynImage");
oDynImage.Open(300, 300);
oDynImage.Color = 0xFF0000;
oDynImage.Line(100, 100, 200, 200);
Response.ContentType = "image/png";
Response.BinaryWrite(oDynImage.Image);
oDynImage.Close();
Reference
Colors
Colors are represented by 24-bit numbers. The high 8 bits are the
red component; the middle 8 bits are the green component; and the low
8 bits are the blue component.
This is exactly the same way HTML names colors, so if you know what
<FONT color="#FFCC33"> means, you can get the same color with the
statement
oDynImage.Color = &hFFCC33 (VBScript)
oDynImage.Color = 0xFFCC33; (JScript)
Otherwise, you can use this formula to determine your color:
color = red * 65536 + green * 256 + blue
where red, green, and blue are integers between 0 and 255, inclusive.
Methods
Arc(x1, y1, x2, y2, x_start, y_start, x_end, y_end)
Draws a partial arc of an ellipse. x1, y1, x2, and y2 are
interpreted as in Ellipse( ). An imaginary line is then drawn from the center of the
elipse to (x_start, y_start); where this line intersects the ellipse, the
arc begins. The arc is then drawn counter-clockwise until it intersects a similar imaginary
line drawn from the center of the elipse to (x_end, y_end). The color of the
arc is indicated by the Color property; its width is indicated by the LineWidth
property.
Close( )
Ends all drawing and releases the memory used by the DynImage object. It is called automatically
when the object is destroyed, but can be called directly for languages that do not have deterministic
garbage collection.
Ellipse(x1, y1, x2, y2)
Draws an ellipse bounded by a rectangle with the top-left corner at (x1, y1) and
bottom-right corner at (x2, y2). The interior color of the ellipse will be equal to
the property FillColor. The border will be drawn with the color indicated by the
Color property; its width will be the size indicated by the LineWidth property.
GetPixel(x1, y1) returns integer
Gets the color of the pixel located at (x, y). See the colors
section for more information on how interpret the returned value.
ImageHeight(filename)
Retrieves the image height in pixels of the file specified by filename.
ImageWidth(filename)
Retrieves the image width in pixels of the file specified by filename.
Line(x1, y1, x2, y2)
Draws a line from (x1, y1) to (x2, y2) with the color indicated by
the Color property and with a width indicated by the LineWidth property.
LoadImage(x1, y1, [x2, y2,] filename)
Loads the image indicated by filename and copies it to coordinates (x1, y1).
The file must be a Windows bitmap file (BMP or DIB). The parameters x2 and y2 are optional; if
present, the image file will be stretched to fit the rectangle with top-left corner at
(x1, y1) and bottom-right corner at (x2, y2).
Open(x, y)
Creates a new, blank image of size x by y pixels. This method must be called first before
any drawing occurs. The inital value of all the pixels will be equal to the property FillColor.
Pie(x1, y1, x2, y2, x_start, y_start, x_end, y_end)
Draws a filled-in pie slice. x1, y1, x2, y2,
x_start, y_start, x_end, and y_end are
interpreted as in Arc( ). The interior color of the pie slice will be equal to the
property FillColor. The border will be drawn with the color indicated by the Color
property; its width will be the size indicated by the LineWidth property.
Rectangle(x1, y1, x2, y2)
Draws a rectangle with the top-left corner at (x1, y1) and bottom-right corner at
(x2, y2). The interior color of the rectangle will be equal to the property FillColor.
The border will be drawn with the color indicated by the Color property; its width will be the
size indicated by the LineWidth property.
SaveImage(filename)
Saves the image as a PNG file to the file specified by filename.
SetPixel(x, y, color)
Sets the single pixel at (x, y) with the color indicated by color. See the colors
section for more information on the range of possible values for color.
TextHeight(string)
Calculates the height in pixels of the text string specified by string, given the current font.
TextOut(x, y, text)
Draws text indicated by text at location (x, y). The apperance of the text is indicated
by the FontAngle, FontFace, FontItalic, FontSize, FontWeight, and
TextAlign properties.
TextWidth(string)
Calculates the width in pixels of the text string specified by string, given the current font.
Properties
Color (integer)
The color used for drawing text, lines, or borders. See the colors section
for information on the range of possible values. Default value is 0x000000 (black).
FillColor (integer)
The color used to fill the interior of rectangles, ellipses, and pie slices. See the
colors section for information on the range of possible values. Default value is
0xFFFFFF (white).
FontAngle (integer)
The angle at which text will be drawn, in degrees. Default value is 0.
FontFace (text)
The font face used for drawing text (ex: "Times New Roman", "Courier", "Palatino"). Default value is "Times New Roman".
FontItalic (integer)
If non-zero, text drawn will be italic. Default value is 0.
FontSize (integer)
The size of the font, in points. Default value is 12.
FontUnderline (integer)
If non-zero, text drawn will be underlined. Default value is 0.
FontWeight (integer)
The weight of the font. Must be an integer between 0 and 1000. Typical values are 400 for normal text, 700 for bold text. Default value is 400.
Image (byte array)
The image in compressed PNG format, suitable for sending to Response.BinaryWrite.
LineWidth (integer)
The width of lines or rectangle/ellipse borders, in pixels. Default value is 1.
TextAlign (integer)
The alignment of the text. Alignment in the horizontal direction can be one of the three values:
Left aligned: 0
Centered: 1
Right aligned: 2
Alignment in the vertical direction can be one of the three following values:
Top aligned: 0
Middle aligned: 4
Bottom aligned: 8
To combine horizontal and vertical alignment, add the two values together. Default value is 0 (top-left alignment).
Transparent (integer)
If not equal to -1, indicates the color of pixel which will be rendered as transparent.
See the colors section for information on the range of possible values. Default value is -1
(no transparent pixels).
Please note that Internet Explorer (all versions) and Netscape Navigator (version 4)
do not render transparent PNGs transparently.
Licensing + Contact Information
This software is beggarware. You can use it for free, but if you find this
object useful, please help an out-of-work dotcom-era veteran with a $20 bill
or whatever small change you can find in your pockets. Especially if you use
it for commercial purposes. Source code is also available for the asking.
Chris Ashton
16329 Lake Hills Blvd
Bellevue, WA 98008
cashton@oz.net
AIM: StAlyoshaK / ICQ: 2359073
You can also send donations to cashton@oz.net via PayPal.
Standard disclaimers apply, esp. the bit about no warranty, expressed or implied,
please don't use this for mission-critical, people-will-die-if-it-has-a-bug
applications, etc, etc. You know the drill.