Blog

The Haycroft Media Blog covers all aspects of website design and development from the web browsers being used through to the standards that govern the world wide web. As a website design and development company, it is imperative that we keep abreast of all the latest news and happenings in our field, and here we present the major stories along with tutorials, tips and other web-programming related items.

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:

<img src="logo.php?text=<?php bloginfo('name'); ?>" />

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['text'])):
	$helloworld = $_GET['text'];
	$helloworld = str_replace(' ', PHP_EOL.'  ', $helloworld);
else :
	$helloworld = "Lifetime<br />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.

[ Back ]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Facebook Comments