« The point of the other blog | Main | Oh happy day.ter »

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.

TrackBack

TrackBack URL for this entry: https://ithink.ch/blog/tb.cgi/4.

Make sure JavaScript is enabled before using this URL. If you would like to ping my blog but can't, please do send me an e-mail at os3476 at this domain.

A few blogs ago, I mentioned that I wanted to install this cool button maker on my server. Well, after dropping the code on my server, everytime I tried to use it I would get this error: "Cannot Initialize new... [Read More]

Comments

hi, i’m right at the beginning of learning php… your source code says:

$letters = imagecreatefrompng( “silkscreen/font.png” );

so, were can i get this “font.png” ??? Seems, that there is something i haven’t understood…

thanks in advance, michael

My mistake, I forgot about the font. Since Bill Zeller didn’t explicitely mention whether this one is stealable, I’ll add a link to his site. You should make a folder named silkscreen next to the PHP script and put font.png inside.

Damn. I’m trying to get your script to work, as I couldn’t get Bill’s to work either. I keep getting the error “The image “http://etc.” cannot be displayed, because it contains errors.”

Any suggestions?

I get the same error as Rob, same as with the original script…no blank lines at the end of the file, either.

Just to let you know, my host got everything sorted out and no more errors - turns out PHP got b0rked during a system reinstall, so it seems they recompiled it. Thanks for your help trying to figure out what was up. Your mods work like a charm; it’s nice to not have to figure out the bar and right text position.

I’m interested in playing around with this script, but I can’t find the ‘font.png’ file anywhere. Any chance you could email it to me?

Dear Friend

I want to try the button maker script but can’t find the font.png anywhere. can you mail it to me please. Another question? Does your version include an interface??

Regards
Luis

font.png can now be downloaded from this site.

I would like to know how to apply a GUI to this so that I can create a button generator with INPUTS. Does anyone know how I would go about doing that?

Adam Kalsey made one for the original script. It has clever JavaScript colour palettes.

If you want to make your own, you can start by writing an HTML form with input fields named after the script’s parameters, like here.

The next step would be to make a script that prints the form and displays the image by calling the button script with the new parameters, like Adam did.

I need Markdown in comments.

http://www.signgenerator.org has a button maker widget ;)

Hi: How to use the scripts to build a page like this? http://kalsey.com/tools/buttonmaker/

I want to add a buttonmaker to my site http://www.webdirectory123.com/ Where to get the scripts?

The script is here:Button 0.2.

In order to make a page like you mentioned earlier, you need to write a PHP or CGI that displays the form, and when you submit it generates a page with an img tag whose source is the button PHP script with the parameters taken from the submitted form data. You can also redisplay the form with the last values filled in to make tweaking easier.

Post a comment

Make sure JavaScript is enabled before posting a comment. If you would like to post a comment but can't, please do send me an e-mail at os3476 at this domain.

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