Making a Dynamic Text Sig|
How showing your IP on an image is done.
By Red Squirrel
Most of you probably have seen those forum signatures that show your IP and other information. You might be wondering how in the world is it done. Well this article will attempt to explain this to you. If you read our other article on making a sig with an image that changes, you have learned how you can actually make a fake image file that is really php but to the browser, is an image. The dynamic text/ip sig uses the same concept, but different code.
If you have read the other sig article and already understand the concept, you can skip to the next page. Otherwise, read on.
First, what we want to do is setup a folder where .jpg files will run as php. So make a folder called phpsigs and put this in your .htaccess file:
That will simply force all files to run in the php parser. You can go into more htaccess stuff to only make certain files be affected and what not, but to keep things simple, we'll just do it to all files. You just have to make sure not to put anything else in this folder. Only the .htaccess file and the fake image file.
Secondly, we need to create a fake image file. By fake I simply mean that it's not a real image, but code. Let's call it siggy.jpg and put it in the phpsigs. The actual image that will be displayed as the sig can be stored anywhere, on, or outside of the server. The image has to be png, for the code we will use.
On the next page, we'll take a look at the code for this sig.
||Pages:  
Latest comments (newest first)|
Posted by Onykage on January 01st 2006 (16:37)|
There is a way to add the random factor without the read/write perms. Just use the rand() syntax. IE if you have 5 images then set something like the following:
|$someStringName = rand( 1, 5 );|
if( $someStringName == 1 ) .. pick some image..
if( $someStringName == 2 ) .. pick some image..
if( $someStringName == 3 ) .. pick some image..
if( $someStringName == 4 ) .. pick some image..
if( $someStringName == 5 ) .. pick some image..
in the php docs on php.net will explain the restrand( min, max );
Also you can use the imagettftext syntaxt. This allows for a slightly more presice text insertion. PS. if you dont know already, to use a ttf font that font must be in the same dir as the php source file.
Posted by Cold Drink on July 07th 2005 (23:22)|
As a side note, that random text code is quite nasty. You could do this:
|$text = Array('ichi', 'ni', 'san', 'shi');|
$random_index = rand(0, count($text) - 1);
$random_text = $text[$random_index];
It is much easier to maintain this way, too.
Posted by Streety on July 07th 2005 (17:27)|
Are both the arial.ttf file and omfghax.png in the same directory?
I really don't know what to suggest. If your host is configured with the GD library I can see no reason why it wouldn't work.
Posted by Streety on July 07th 2005 (16:00)|
$number = rand(1,28);
if($number==1)$string2 = "ALL THE WAY TO 3000";
if($number==2)$string2 = "127.0.0.1";
if($number==3)$string2 = "GB2OMFGHAX?";
if($number==4)$string2 = "ALL YOUR MOMS ARE BELONG TO ME";
if($number==5)$string2 = "ROFLMAOBBQ";
if($number==6)$string2 = "HTTP://WWW.OMFGHAX.COM";
if($number==7)$string2 = "I STOLE UR MEGAHURTZ!!11!";
if($number==8)$string2 = "KING OF THE INTERNETS";
if($number==9)$string2 = "IF IT AIN'T HERE IT AIN'T TRUE";
if($number==10)$string2 = "WHAT!";
if($number==11)$string2 = "1+3+3=7";
if($number==12)$string2 = "WE LOVE TO SEE YOU SMILE";
if($number==13)$string2 = "I'D BUY THAT FOR A DOLLAR";
if($number==14)$string2 = "YOU MAY ALREADY BE A WINNER";
if($number==15)$string2 = "TEACHING YOU NEW MEANING OF WORD VIOLATION";
if($number==16)$string2 = "NOW WITH 100% LESS SPYWARE";
if($number==17)$string2 = "OH IT'S BEEN BROUGHT";
if($number==18)$string2 = "IT'S MAGIC";
if($number==19)$string2 = "TOUCH IT!";
if($number==20)$string2 = "EVERYTHING BUT THE RABBI";
if($number==21)$string2 = "WHY, THANK YOU";
if($number==22)$string2 = "9 INCHES OF LIMP DICK FOR YA butt";
if($number==23)$string2 = "SPAM!";
if($number==24)$string2 = "MARDI GRAS WITHOUT THE TITS AND BOOZE";
if($number==25)$string2 = "HMMMMMMM...";
if($number==26)$string2 = "DIE IN A FIRE!";
if($number==27)$string2 = "THIS SPACE FOR RENT";
if($number==28)$string2 = "1-(900)-OMFG-HAX";
$im = imagecreatefrompng("wtf.jpg.png");
$color = imagecolorallocate($im, 178, 187, 201);
$font = 'arial.ttf';
imagettftext($im, 20, 2, $px, $py, $color, $font, $string2);
Hope that helps.
Posted by Streety on July 07th 2005 (14:56)|
|QUOTE (Red Squirrel @ Jul 17 2005, 07:21 PM)|
|Actually arn't you limited to non true type fonts when using dynamic image text? I may be wrong though, never tried anything but default. |
The function imagestring only has the one preset but imagettf
text is specifically for use with true type fonts.
There are a couple of things with your code.
When I tried to use it I got the following error
|Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE or '$' in /home/jmstre/public_html/images/help/dynamic_pic_help_on_code.php on line 46|
Looking at line 46 we have
|imagettftext($im, 0, 2, &px, $py+13, $string2, $color, $font);|
For the variable px you used & rather than $.
So if we fix that we get
|The image “http://www.jmstreet.info/images/help/dynamic_pic_help_on_code.php” cannot be displayed, because it contains errors.|
After checking various things I came back to the same line. Alot of the variables are in the wrong places. It should be set out as below:
|imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )|
After you do all that you get this . . .
I've changed the x and y values so it doesn't totally overlap your image (I couldn't be bothered making my own) but if you fix that one line it should work.
One other thing to note though is that your random number isn't going to be very random. You need to seed the random number generator before you use it. The best way to do it is to include this code before you call the random number function;
I'm not sure why exactly this is the best way but I'm informed that it is. It certainly works though.
|View all comments|