PHP

Random Text For Signature Used in Forum/Bulettin Board

There are so many signature generator for forum/bulettin board. And surely we can try to create our own, fully personalized as follow:
random quote

I’ve written this script at September 2004, and now time to share the code.

First, create a text file. Name it quote.txt and write down your text/quotes. One sentence per line.

MAGIC QUOTES by Yeni Setiawan
Another day gone forever
No dog can chew my bone
Catch the falling stars and put it in your pocket
Visit http://sandalian.com for more stuffs
Also visit my personal blog at http://the.sandalian.com/
Hi, I'm 24 years old and looking for sweet girl to date out
Quick brown fox jumps over the lazy dog

Now let’s start coding. First, since we’re going to use image for this thing, tell to browser that this is a PNG file. We don’t use JPG here, I hope you know the reason.
< ?php header ("content-type: image/png"); ?>

Then define backgound color:< ?php /* define background-color with script.php?bg=r:g:b if no background color, define as white 250,250,250 */ $col = $_GET[bg]; if(!$col){ $col = "255:255:255"; } $col=explode(":",$col); ?>

Next step is read your text file, put it in array and fetch a random string< ?php //read the quote from quote.txt, results an array $quote=file("quote.txt"); $quote=str_replace("n","",$quote); $quote=str_replace("r","",$quote); //randomize the array srand ((float) microtime() * 10000000); $rand_keys = array_rand($quote, 2); $now= $quote[$rand_keys[0]]; ?>

Last but not least, let’s draw an image:< ?php $width = strlen($now); $width = ($width*6.5); $im = @imagecreate ($width, 18) or die ("cannot initialize new gd image stream"); $background_color = imagecolorallocate ($im, $col[0], $col[1], $col[2]); $text_color = imagecolorallocate ($im, 0, 0, 0); imagestring ($im, 2, 3, 3, """.$now.""", $text_color); imagepng ($im); ?>

To use this script, simply point it as an ordinary image file. Using &lt;img src=”path/to/file.php” /&gt;. You can change its background color by adding additional parameters. xxx:xxx:xxx which is RGB value.

&lt;img src=”path/to/file.php?bg=255:100:030″ /&gt;

Happy coding! ^_*

3 Comments

  1. OR, if you are looking to get your image signature rotated, you can use this cool site! http://www.rotatingsignature.com

  2. Unlaliblenova

    Was ist das?

  3. skibTinkoveks

    ???…

Leave a Reply