tags:

views:

23

answers:

3

Hello everyone, I'm trying to get the following done:

I have a set of fonts and I want users to be able to try these fonts online, but i want the result to appear in an image so no one can use the font unless they buy it. I found an example about what I exactly want here. Can anyone tell me how to do it ??

Thanks

A: 

If you don't need to display user-entered text, won't using static images be the KISS solution?

Tobiasopdenbrouw
I think the ability to display user-entered text is exactly what's being requested
David Hedlund
It very well may be, in which case, your answer is the thing. +1
Tobiasopdenbrouw
+4  A: 

The src of the image is a server side page that renders an image:

So what you want to do is to set the src to an aspx-page with the input text as a querystring. From that you create a graphics object, and use the font to draw the specified text onto that

excerpt from article

private void button4_Click(object sender, System.EventArgs e)
{
  Graphics grf = this.CreateGraphics();
  try
  {
    grf.Clear(Color.White);
    using (Font myFont = new Font("Arial", 14))
    {
      grf.DrawString("Hello .NET Guide!", myFont, Brushes.Green, new PointF(10, 100));
    }
  }
  finally
  {
    grf.Dispose();
  }
}

After that, you need to do a Response.Clear() so that you don't get any other text content rendered, and set Response.ContentType = "image/jpeg"; (or whatever content type you'll be using), and then write your image to the response output buffer.

David Hedlund
Thank you David, I think that would solve the problem.
Naruto
A: 

There are a number of solutions to this problem :

  1. render the font on the server - this is probably the best approach and from a copyright pov (if any) the safest. The answer from David outlines an approach.

  2. Render the font on the client. For a busy site this would place less load on your server. There are a number of solutions in javascript, my favourite being Cufon. The browser downloads the cufon runtime as well as a font file and this is rendered by the browser. You need to be aware of font licensing when using this approach, but it does require no setup on the server, and can even be used offline.

You can also use Flash to render the fonts, without licensing issues.

James Westgate