« May 23, 2003 | Main | June 3, 2003 »

May 29, 2003

Steal this button generator

Bill Zeller wrote a nice PHP script that uses GD to make 80x15 buttons like the ones found at Steal These Buttons. I downloaded it to so I could make my own buttons quickly on my local machine and the next minute I found myself hacking through the code and modifying it.

The only difference from the outside is that the central bar and the right hand side text now position themselves automatically if no value is given for the corresponding parameters. Under the hood, since I can be pretty maniac when programming sometimes, I grouped all the default values together, I put the code for text drawing into a function and I made it easier to take the parameters from the $_GET or $_POST globals in case register_globals is turned off, like on a freshly installed PHP 4.3. I even considered (and wrote some code for) using constants for the dimensions of the image and calculate all the other values, but I decided it was not worth the trouble since the text is bitmapped anyway.

Here is the source.

Update (June 4, 2003): The font must be downloaded on Bill Zeller’s site. font.png should go into a folder named silkscreen next to the PHP script.

Update (February 9, 2004): I forgot to mention it, but Rob found the solution to his problem:

It turns out the problem is that I have an older version of GD, and it doesn’t support imagecreatetruecolor(). I changed the directive to imagecreate(), and it works fine now.

Update (October 11, 2004): font.png is now available here. It should go into a folder named silkscreen next to the PHP script.

Do not meddle in the affairs of Coding Ninjas, for they are subtle and quick to anger.