Forum Moderators: open

Message Too Old, No Replies

generating an image dynamically and serving it

using ASP / IIS

         

httpwebwitch

6:22 pm on Oct 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want a script that will create a GIF rendering of some text, with a chosen font & wrapped to a certain width... then I want to deliver that text to the page. The text is fed in from elsewhere and changes constantly, so cacheing or pre-rendering is not an option. It has to be fast.

My intent is to display text on the screen which can't be read by spiders & bots.

how could it be done?

Easy_Coder

3:00 pm on Oct 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can accomplish this with .net.

- The width is set when you cut the bitmap object but I can't tell you if that will auto wrap. You'll have to give that a try.

- The font is set in the System.Drawing.Font namespace.

- As for feeding the data from elsewhere, just create a database or FileIO call to fecth that data and plug those results in where I hardcoded the email address.

I use this code in a UserControl to display an email address as an image so that spiders don't pick it up:

// Create a bitmap object
Bitmap objBmp = new Bitmap(175, 20);

// Create a graphics object
System.Drawing.Graphics objGraphics = System.Drawing.Graphics.FromImage(objBmp);

// Set the background color to white
objGraphics.Clear(Color.White);

// Render as anti alias for a better quality image
objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;

// Create a Font object and select a font & size
System.Drawing.Font objFont = new Font("Arial", 10, FontStyle.Regular);

// What's the text that should appear on the image
objGraphics.DrawString("mymail@myaddress.com", objFont, Brushes.Blue, 3, 3);

// Set the content type to gif
Response.ContentType = "image/GIF";

// Stream the image out to the http header
objBmp.Save(Response.OutputStream, ImageFormat.Gif);

// Because were working with the graphics library it's recommended
// practice that we force cleanup to occur.
objFont.Dispose();
objGraphics.Dispose();
objBmp.Dispose();

httpwebwitch

2:37 pm on Nov 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



warning: I'm a total newbie at this. I've done it before with PHP, but ASP is relatively unfamiliar territory. I cut and pasted your code into a test page, and got an error on the first line: object not supported.

Our server is indeed .NET, and I have arranged to get some cooperation from the server admin for this... any advice you can give regarding setup is crucial.

Do I need a special DLL library, extension or something?

Easy_Coder

6:07 pm on Nov 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



yeah your not going to be able to just cut n paste this.

that code needs to be dropped into a UserControl. then drag that control onto the page where you want to display the image. You will need to compile the code before attempting to run it too.

httpwebwitch

2:37 pm on Nov 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks easycoder!

Easy_Coder

6:14 pm on Nov 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



did it work out for you?