martes, 1 de diciembre de 2009

Convert Text into PNG Image using PHP

We are currently working on a Wordpress MU theme that requires logos to be generated on the fly.

Fortunately the logos will just make use of a simple script font, but we still need some means of auto-generating them. We started with a great tutorial at Vision Master Designs and tweaked it slightly to fit in with Wordpress and the specification of the client.

Firstly, and fortunately, the name of each of the WPMU blogs would be the name required in the logo. This meant that we could pass "bloginfo('name')" in the text variable:


" />


Secondly, all the site names would be two words and these needed to be spread over two lines. This required a small addition to the code that simply replaces the whitespace between the two words with a PHP_EOL (end of line) call.


if (isset($_GET)):
$helloworld = $_GET;
$helloworld = str_replace(' ', PHP_EOL.' ', $helloworld);
else :
$helloworld = "Lifetime
Experiences";
endif;


With those two additions, we now have a theme that automatically generates logos on the fly. Perfect for a client who needs to be able to publish sites quickly and easily.

1 comentario: