Creating Graphics PHP/GD

Joined: 11/28/2008

I am working on a project where I need to:

1) Take input text and font style from a form.
2) Turn that input in into a graphic (a choice of several script fonts)
3) If possible I need to merge that text into an existing PNG file with transparency and keep the transparency.

If I can do this in PHP I'm sure it will be with GD...can anyone give me any direction this?

Thanks,
Chris

G&G Podcast Host
Matt Farina's picture
Joined: 06/01/2006
Font Type?

I take it you are using true type fonts?

I have not done this but there is a drupal module that does this at http://cvs.drupal.org/viewvc.py/drupal/contributio....

It uses GD2 and you might be able to get something from the code.

Matt Farina
Geeks and God Former Co-Host
www.mattfarina.com

Joined: 05/06/2007
Anything's possible :)

I've done tons of PHP work with images, and usually just used imagecreatefrompng(), but someone on php.net mentions that to retain transparency you'll need to imagecreatetruecolor() first, imagecopyresampled(), then add custom text and whatnot.
Then either save the PNG or display it using imagepng()

I've never used transparency in PNG's with PHP myself (primarily because not all browsers properly support it, and I don't care for browser-specific hacks if I can avoid them), but it definitely looks like something I might start looking into soon to auto-generate header files for articles.

I'd recommend posting back if you make it work, I'd love to see the results, or attempt to help if you run into any road blocks. (and yes, you'd be using the GD2 library which has been packaged with most recent versions of PHP for a while now)

The Geekons Christian Technology Podcast (not as good as G&G, but whatever)