Page 2 of 2
Making a dynamic text sig
Posted: Sat May 28, 2005 6:27 am
by Streety
Well most thngs are possible but that doesn't mean it's simple. There isn't a function that will automatically centre the text. You would need to calculate the length of the string being written to the image and then start half that distance away from the centre point.
You can easily get the length of the string using
strlen. You then need to multiply this number by the width of each character (this will vary depending on the font you use) to get the total length of the string.
Archived topic from Iceteks, old topic ID:2012, old post ID:27155
Making a dynamic text sig
Posted: Sun Jul 17, 2005 3:57 pm
by Streety
Can you give me a little more information on your situation? It is all but impossible to help with what you have said so far.
Archived topic from Iceteks, old topic ID:2012, old post ID:28254
Making a dynamic text sig
Posted: Sun Jul 17, 2005 7:02 pm
by Streety
I'm glad you got it working.
imagestring only has the one preset font. To use different fonts you will need to use
imagettftext. It works in much the same way but if you have any questions just post them and I'll try and help.
One piece of advice though; do a search for ttf fonts and come up with something more exciting than ariel.
Archived topic from Iceteks, old topic ID:2012, old post ID:28260
Making a dynamic text sig
Posted: Sun Jul 17, 2005 7:21 pm
by Red Squirrel
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.
Archived topic from Iceteks, old topic ID:2012, old post ID:28263
Making a dynamic text sig
Posted: Mon Jul 18, 2005 2:56 pm
by Streety
Red Squirrel wrote: 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 image
ttftext 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
[quote=-></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td> 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[/quote]
Looking at line 46 we have
Code: Select all
imagettftext($im, 0, 2, &px, $py] The image “http://www.jmstreet.info/images/help/dynamic_pic_help_on_code.php” cannot be displayed, because it contains errors.[/quote]
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:
[code]imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )[code]
After you do all that you get this . . .
[img]http://www.jmstreet.info/images/help/dynamic_pic_help_on_code.php[/img]
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;
[code]srand((double)microtime()*1000000);[code]
I'm not sure why exactly this is the best way but I'm informed that it is. It certainly works though. ;)
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:2012, old post ID:28314[/size][/color]
Making a dynamic text sig
Posted: Mon Jul 18, 2005 4:00 pm
by Streety
Directory structure:
Code: Select all
+
|
+---arial.ttf
|
+---dynamic_pic_help_on_code.php
|
+---wtf.jpg.png
[code]
dynamic_pic_help_on_code.php:
[code]<?php
header("Content-type: image/png");
$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';
$px=150;
$py=40;
imagettftext($im, 20, 2, $px, $py, $color, $font, $string2);
imagepng($im);
imagedestroy($im);
?>[code]
Hope that helps.
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:2012, old post ID:28318[/size][/color]
Making a dynamic text sig
Posted: Mon Jul 18, 2005 5:27 pm
by Streety
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.
Archived topic from Iceteks, old topic ID:2012, old post ID:28332
Making a dynamic text sig
Posted: Mon Jul 18, 2005 11:22 pm
by Cold Drink
As a side note, that random text code is quite nasty. You could do this:
Code: Select all
$text = Array('ichi', 'ni', 'san', 'shi');
$random_index = rand(0, count($text) - 1);
$random_text = $text[$random_index];[code]
It is much easier to maintain this way, too.
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:2012, old post ID:28338[/size][/color]
Making a dynamic text sig
Posted: Tue Jan 31, 2006 4:37 pm
by onykage
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:
Code: Select all
$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..[code]
in the php docs on php.net will explain the rest
[url=http://us2.php.net/manual/en/function.rand.php]rand( min, max );[/url]
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.
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:2012, old post ID:33838[/size][/color]