views:

75

answers:

3

I got this question from my cousin:

"What will be the best way to create a similar working website just like: http://www.plakletters.nl". I have looked into the website and think that to start of with i'm gonna help my cousin write a script that loads all fonts installed on the system into a dropdownlist. This dropdownlist will post a font value back to the page and will create images with the input of a user that comes from a textbox. This images will have to be created server side, and I also want to give the users the ability (in the future) to lay their own text over an uploaded image, to see what the result will look like on their own image. I found some information about how to create images using php, I don't know if php can output a list of installed fonts from the system it's running on. What scripting language would you use to get this job done? Keep in mind i would just like to start with outputting some images based on user input using a scripting language.

+5  A: 

ImageMagick. This can be called from the shell or with the Perl bindings or with bindings for a lot of other languages. See http://www.imagemagick.org/Usage/text/

luqui
+1  A: 

If you use perl, another alternative is the Imager module. This tends to be a simpler install than ImageMagick/PerlMagick.

Adding text looks like:

use Imager;

my $img = Imager->new(file => "foo.jpg") || die Imager->errstr();

my $font = Imager::Font->new(file=>"Arial.ttf");

$img->string(
    x => 50, y => 70,
    string => "Hello, World!",
    font => $font, size => 30,
    aa => 1, color => 'white'
);
$img->write(file => "foo2.jpg");

More details here.

Gavin Brock
+1  A: 

Well, my favorite language is Python, so that's what I'd use! :) The PIL module gives you image manipulation capabilities.

Although I have never used PIL before, I put together the following with a few minutes of research and experimentation:

import Image
import ImageDraw

im = Image.open("my_image.png")
draw = ImageDraw.Draw(im)
draw.text((0,0), "my text")
im.save("my_out.png")

As you might have guessed, this just opens a PNG file, writes "my text" into it in the upper left corner and saves the modified image with a new name. I do not know how to get the font information you're looking for, but expect there's a module that can help with that also.

GreenMatt