Drawing arrows in ASP

ImageMagickObject is a Windows COM+ interface to ImageMagick. COM+, Visual Basic, and Delphi users should post to this discussion group.
Post Reply
lobstar85

Drawing arrows in ASP

Post by lobstar85 »

Hi guys, I thought the lack of ASP examples was pretty bad. I can do most of the things I want from the command line, but the big problem is that using imagemagick with ASP has some very different syntax. It took me quite a while of trial and error to figure out the syntax I needed because I wasn't able to see what I was doing wrong.

The code below is what I use to draw an arrow with imagemagick. It comes with a black stroke and a fill. I start out with a 60x60 canvas but if you need it bigger, you can always modify the generate statement. You can pass it a color, direction (degrees from north), and size (up to 60). It's probably some bad code to do some of the things I've done, but my experience with this is very minimal.

Code: Select all

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<%
'Get color and direction from the user
strColor = Request.QueryString("color")
strDirection = Request.QueryString("direction")
strSize = Request.QueryString("size")

'Default color of blue
if strColor = "" then strColor = "blue" end if

'Default orientation of North
if strDirection = "" then strDirection = "0" end if

'Default size of 18
if strSize = 0 then strSize = "18" end if

'Get scaling factor, by default, 30%
factor = (cInt(strSize)/60)*100
strFactor=cStr(factor) + "%"


'Make the imagemagick object
set img = server.CreateObject("ImageMagickObject.MagickImage.1")

'Make a place to save the image in RAM
Dim myArray(0)

'Rotate arrow because by default it is facing south
strDirection=strDirection+180

'Tell imagemagick we want a PNG
myArray(0)="PNG:"

'Tell webpage we are putting out a PNG
Response.contentType="image/PNG"

'Draw Arrow thats 60x60, no background, 2 pixel stroke filled with the users color of choice, rotated the way the user wants, and then shrunk by passed in factor, saved to RAM
img.convert "-size=60x60","-background","none","xc:transparent","-stroke=black","-fill=" & strColor,"-strokewidth=2","-draw=polygon 5,5 30,54 54,5 30,24","-rotate",strDirection,"-trim","-resize=" + strFactor,myArray

'Output the PNG image
response.binaryWrite myArray
%>

I hope this helps anyone else confused by the syntax. I really wanted to use a path but I couldn't figure out how to get imagemagick to do that in ASP. Feel free to improve on it or whatever!
Post Reply