0

I have an asp.net website and want to show users information in some pages. One of their infos is their email. I want to create an image from email and show it instead of text so that the spammers can not obtain it... how can I create image from text? or is there any other way to achieve it?

mjyazdani
  • 2,110
  • 6
  • 33
  • 64

1 Answers1

4

Check this answer, it should help guide you in the right direction. It draws text on an image.

https://stackoverflow.com/a/2070493/907388

This article also is a great example to generate an image from text or convert text into image

http://chiragrdarji.wordpress.com/2008/05/09/generate-image-from-text-using-c-or-convert-text-in-to-image-using-c/

You can also generate images from text server side with imageMagick

EDIT:

The methods above assume you will save the image. The following method below will encode the image object to Base64 string so you do not have to save the image directly.

public string ImageToBase64(Image image,System.Drawing.Imaging.ImageFormat format) 
{
  using (MemoryStream ms = new MemoryStream()) 
  {
    // Convert Image to byte[]
    image.Save(ms, format);
    byte[] imageBytes = ms.ToArray();

    // Convert byte[] to Base64 String
    string base64String = Convert.ToBase64String(imageBytes);
    return base64String;
  }
}

After encoding the image, use the base64String return value from ImageToBase64 in an img as such:

<img src="data:image/png;base64, iAAANSUhEQAA..." alt="my encoded image"/>

Just replace iAAANSUhEQAA... with the actual value, which could be quite large depending on the size of the image.

And one more note, data-uri do not work in IE6/7

credit: http://www.dailycoding.com/Posts/convert_image_to_base64_string_and_base64_string_to_image.aspx

Community
  • 1
  • 1
pbojinov
  • 907
  • 9
  • 17
  • 2 first links shows how to create image in c#.net ... I should save them and then use them in asp.net , Am I right? Is there any way to use them without saving them? or how can I remove them after closing the window? By using image magic I should save them too, yes? – mjyazdani Apr 16 '13 at 06:57
  • Yes, you are right. you should save them and use them in asp.net. The alternative to saving them is to encode the images to `Base64` and use that as the ``. See my answer edit above on how to do this. Hope this helps – pbojinov Apr 16 '13 at 17:26