We help IT Professionals succeed at work.

How to write text onto a picture file in asp or asp.net?

DanJourno asked

i've got a website written in asp.

Ive created a fancy button, however I want to write a label onto the button dynamically.
I used to use a component called ASPPainter however it doesnt seem to work on Windows Server 2008.

I need a script that will take a gif file, and write a string onto it and stream it to the browser (or save it as a temporary file for later use).

Does anyone have one? Written in asp or asp.net.

Many thanks
Watch Question

Wayne BarronAuthor, Web Developer
Top Expert 2009

You can always contact the developers and ask if there are any plans for making the component work with 2008
They're email address is on the main page, but not sure if it is still good
Concidering that it might be a SPAM trap.
(Never put your linkable email address on your page, bad SPAM things will happen)

Good Luck

Can't you simply make a div the same size as the gif file, then make the gif it's background image and then write inside the div and make the entire div a link if needed?

e.g. lets assume your gif is 100px by 30px
<a href="targetPage.asp">
<div style="width:100px; height:30px; background:url(/images/button.gif) top left no-repeat; text-align:center">Submit Now</div>

/ Tobzzz
i have study the asppainter software so their is no option foe edit a image and make this one a link.
so,choose another software or make two image with link in div.


Tobzzz: the website is centred on the screen, but the div is ancored to the topleft, so when the browser is resized, the div repositions into the wrong location.

Hmm, I would imagine you could do postition:fixed to anchor it dead centre unless your site is variable width in which case it would be trickier. To centre an image would be just as difficult as to centre a div.
Ive got a solution to my original question.
Here is the code I used
<%@ Page Language="VB" %>
<%@ import namespace="System.Drawing" %>
<%@ import namespace="System.Drawing.Imaging" %>


    Dim imgPhoto As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath("../originalimage.jpg"))
    Dim phWidth As Integer = imgPhoto.Width
    Dim phHeight As Integer = imgPhoto.Height
    Dim bmPhoto As Bitmap = New Bitmap(phWidth, phHeight, imgPhoto.PixelFormat)
    Dim drawFormat As New StringFormat
    drawFormat.Alignment = StringAlignment.Center

    bmPhoto.SetResolution(72, 72)
    Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)

    grPhoto.DrawImage(imgPhoto, New Rectangle(0, 0, phWidth, phHeight), 0, 0, phWidth, phHeight, GraphicsUnit.Pixel)
    grPhoto.DrawString(request.querystring("line1"), New Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, New RectangleF(0, 16, 132, 64), drawFormat)
    grPhoto.DrawString(request.querystring("line2"), New Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, New RectangleF(0, 31, 132, 64), drawFormat)

<script runat="server" language="vb">
public Sub ShowImage(ByVal bmp As Bitmap)
    ' Clear current content and set returned content type
    HttpContext.Current.Response.ContentType = "image/jpeg"
    ' Save to the Response.OutputStream object
    bmp.Save(HttpContext.Current.Response.OutputStream, _

End Sub

Open in new window

Wayne BarronAuthor, Web Developer
Top Expert 2009

Awesome, Congradulations!