PHP Images... I can't make one. :( |
Author: |
Message: |
Moo
Full Member
Posts: 395 Reputation: 19
Joined: Jun 2004
|
O.P. RE: PHP Images... I can't make one. :(
I have just realized that my files were blank... due to the fact that i was out of space it now works I have this :
I am trying to take out a part of the cache txt i have.
This post was edited on 01-22-2005 at 11:15 PM by Moo.
|
|
01-19-2005 09:59 PM |
|
|
Moo
Full Member
Posts: 395 Reputation: 19
Joined: Jun 2004
|
O.P. RE: PHP Images... I can't make one. :(
its too hard... i need something like XML
Is it possible to just take a picture (like 5 secs after object is loaded) of a swf object?
This post was edited on 01-19-2005 at 10:42 PM by Moo.
|
|
01-19-2005 10:37 PM |
|
|
-dt-
Scripting Contest Winner
;o
Posts: 1819 Reputation: 74
36 / /
Joined: Mar 2004
|
RE: PHP Images... I can't make one. :(
quote: Originally posted by Guillaume
its too hard... i need something like XML
Is it possible to just take a picture (like 5 secs after object is loaded) of a swf object?
ok I've added a simple parseing thing to the code i gave before
code: <?
$handle = fopen("http://www.bungie.net/Stats/PlayerStats.aspx?player=guyguyme2003", "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
$match = InsideTags('<div class="ExpBar" style="width:50"><div class="ExpBarText" style="left:20">','</div></div>',$contents); // uses a regular expression and gets the stuff inbetween those two points and returns it
foreach ($match[1] as $stat){ //just echo's all your stats
echo "$stat <br>";
}
function InsideTags($tag1,$tag2,$html){ //function to grab text inbetween two points
$tag2 = str_replace('/', "\/" ,$tag2);
preg_match_all("/$tag1(.*)$tag2/i", $html, $match);
return $match;
}
?>
now when that script above is run it will goto http://www.bungie.net/Stats/PlayerStats.aspx?player=guyguyme2003 download the whole page and inserts it into $contents.
then because the stats are displayed in the html like so
code: <div class="ExpBar" style="width:50"><div class="ExpBarText" style="left:20">3</div></div>
my code grabs the text inbetween the points code: <div class="ExpBar" style="width:50"><div class="ExpBarText" style="left:20">
and
code: </div></div>
and then puts then in a varible called $match[1] ( $match[0] array holds the whole html of the stat lines )
then it prints all the stats out in order
so currently the script will print out
code: 3
4
1
9
5
It should be easy for you to assign every thing in $match[1] to varibles then print it to your image.
edit:
and also you will need to cache the stats because you dont want it to download your stat page everytime someone vists your image.
This post was edited on 01-20-2005 at 07:06 AM by -dt-.
Happy Birthday, WDZ
|
|
01-20-2005 07:04 AM |
|
|
Moo
Full Member
Posts: 395 Reputation: 19
Joined: Jun 2004
|
O.P. RE: PHP Images... I can't make one. :(
I dont know if I understood fully, but I tried code: <?
$handle = fopen("http://www.bungie.net/Stats/PlayerStats.aspx?player=guyguyme2003", "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
$match = InsideTags('<div class="ExpBar" style="width:50"><div class="ExpBarText" style="left:20">','</div></div>',$contents); // uses a regular expression and gets the stuff inbetween those two points and returns it
foreach ($match[1] as $stat){ //just echo's all your stats
echo "$stat <br>";
}
function InsideTags($tag1,$tag2,$html){ //function to grab text inbetween two points
$tag2 = str_replace('/', "\/" ,$tag2);
preg_match_all("/$tag1(.*)$tag2/i", $html, $match);
return $match;
}
header("Content-type: image/png");
$im = @imagecreate(100, 200)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 1, 5, 5, $match[1] , $text_color);
imagepng($im);
imagedestroy($im);
?>
and got
PS: that was to see if i could make it work.
This post was edited on 01-20-2005 at 10:32 PM by Moo.
|
|
01-20-2005 10:24 PM |
|
|
WDZ
Former Admin
Posts: 7106 Reputation: 107
– / /
Joined: Mar 2002
|
RE: PHP Images... I can't make one. :(
Well, to remove that code that echoes your stats (useless if you want an image output) and also rename the variables so they're easier to understand, delete this code...
code: foreach ($match[1] as $stat){ //just echo's all your stats
echo "$stat <br>";
}
And replace it with this...
code: $rumble_pit = $match[1][0];
$team_skirmish = $match[1][1];
$head_to_head = $match[1][2];
$big_team_battle = $match[1][3];
$team_slayer = $match[1][4];
Now you can use those simple variables in the imagestring() function. The current code is trying to write "$match[1]" on the image, but that's actually an array, so it won't work.
|
|
01-21-2005 04:29 AM |
|
|
-dt-
Scripting Contest Winner
;o
Posts: 1819 Reputation: 74
36 / /
Joined: Mar 2004
|
RE: RE: PHP Images... I can't make one. :(
quote: Originally posted by Guillaume
I dont know if I understood fully, but I tried code: <?
....
header("Content-type: image/png");
$im = @imagecreate(100, 200)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 1, 5, 5, $match[1] , $text_color);
imagepng($im);
imagedestroy($im);
?>
and got
PS: that was to see if i could make it work.
the array highlighted is an array inside an array so you need to reference it like
code: $match[1][X]
(where x is a number from 0 to 3 well if theres more you just keep counting up )
so
code: echo $match[1][0];
would produce your first stat .
then to get your 2nd stat you would do
code: echo $match[1][1];
so to produce your image i would do something like
code: <?
$handle = fopen("http://www.bungie.net/Stats/PlayerStats.aspx?player=guyguyme2003", "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
$match = InsideTags('<div class="ExpBar" style="width:50"><div class="ExpBarText" style="left:20">','</div></div>',$contents); // uses a regular expression and gets the stuff inbetween those two points and returns it
foreach ($match[1] as $stat){ //just echo's all your stats
echo "$stat <br>";
}
$text = array("Stats for map X = $match[1][0]","Stats for map X = $match[1][1]","Stats for map X = $match[1][2]","Stats for map X = $match[1][3]","Stats for map X = $match[1][3]");
header("Content-type: image/png");
$im = @imagecreate(100, 200)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 0);
$line = 5;
foreach ($text as $string){
imagestring($im, 1, 5, $line, $string , $text_color);
$line = $line +10; //makes sure text dosnt overlap so each thing in array $text is on a new line adjust this as you need
}
imagepng($im);
imagedestroy($im);
function InsideTags($tag1,$tag2,$html){ //function to grab text inbetween two points
$tag2 = str_replace('/', "\/" ,$tag2);
preg_match_all("/$tag1(.*)$tag2/i", $html, $match);
return $match;
}
?>
That should work I hope but im not home to test it ill test it later
edit :
blahhhhhhhhhhhhh wdz beat me
This post was edited on 01-21-2005 at 04:40 AM by -dt-.
Happy Birthday, WDZ
|
|
01-21-2005 04:36 AM |
|
|
Moo
Full Member
Posts: 395 Reputation: 19
Joined: Jun 2004
|
O.P. RE: PHP Images... I can't make one. :(
-dt-, I tried your script and I got:
quote: Originally posted by php error
3
4
1
9
5
Warning: Cannot modify header information - headers already sent by (output started at /home/theglas/public_html/guillaumelforum/halo2/index2.php:14) in /home/theglas/public_html/guillaumelforum/halo2/index2.php on line 22
PNG IHDRd$ւPLTEU~mIDATxc` `b10```aX,Yp2./aoT``TIaj!;ǢFQ>pu˨[hQ0 F(` ;GA7:#IENDB`
And WDZ, How do you add line breaks between strings?
This post was edited on 01-21-2005 at 09:04 PM by Moo.
|
|
01-21-2005 08:30 PM |
|
|
segosa
Community's Choice
Posts: 1407 Reputation: 92
Joined: Feb 2003
|
RE: PHP Images... I can't make one. :(
quote: Originally posted by Guillaume
And WDZ, How do you add line breaks between strings?
\n
The previous sentence is false. The following sentence is true.
|
|
01-21-2005 09:02 PM |
|
|
Moo
Full Member
Posts: 395 Reputation: 19
Joined: Jun 2004
|
O.P. RE: PHP Images... I can't make one. :(
quote: Originally posted by PHP error
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/theglas/public_html/guillaumelforum/halo2/index.php on line 33
Parse error: parse error, unexpected T_STRING in /home/theglas/public_html/guillaumelforum/halo2/index.php on line 33
code: <?
$handle = fopen("http://www.bungie.net/Stats/PlayerStats.aspx?player=guyguyme2003", "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
$match = InsideTags('<div class="ExpBar" style="width:50"><div class="ExpBarText" style="left:20">','</div></div>',$contents); // uses a regular expression and gets the stuff inbetween those two points and returns it
$rumble_pit = $match[1][0];
$team_skirmish = $match[1][1];
$head_to_head = $match[1][2];
$big_team_battle = $match[1][3];
$team_slayer = $match[1][4];
function InsideTags($tag1,$tag2,$html){ //function to grab text inbetween two points
$tag2 = str_replace('/', "\/" ,$tag2);
preg_match_all("/$tag1(.*)$tag2/i", $html, $match);
return $match;
}
header("Content-type: image/png");
$im = @imagecreate(100, 200)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 1, 5, 5, $rumble_pit \n $team_skirmish , $text_color);
imagepng($im);
imagedestroy($im);
?>
Did I do something wrong?
|
|
01-21-2005 09:08 PM |
|
|
WDZ
Former Admin
Posts: 7106 Reputation: 107
– / /
Joined: Mar 2002
|
RE: PHP Images... I can't make one. :(
quote: Originally posted by Guillaume
-dt-, I tried your script and I got:
That was because you had to remove the code that echoed text. As I said above, you should get rid of that if you're outputting an image. I see that it's gone in the latest code you posted, so good.
quote: Originally posted by Guillaume
And WDZ, How do you add line breaks between strings?
In a regular string, you would use the line break character as Segosa said, \n. But in an image, you need to increase the vertical coordinate in your imagestring() function to go to a new line (see the $line = $line +10; in dt's code).
quote: Originally posted by Guillaume
Did I do something wrong?
Yeah, this...
$rumble_pit \n $team_skirmish
should be inside a string...
"$rumble_pit\n$team_skirmish"
But like I said, you can't use a line break in an image. You have to do something like this...
code: $line = 5;
imagestring($im, 1, 5, $line, $rumble_pit, $text_color);
$line = $line + 10;
imagestring($im, 1, 5, $line, $team_skirmish, $text_color);
That will create an image with a 1 and a 5 below it. If you want labels, just use strings like so...
code: $line = 5;
imagestring($im, 1, 5, $line, "Rumble pit: $rumble_pit", $text_color);
$line = $line + 10;
imagestring($im, 1, 5, $line, "Team skirmish: $team_skirmish", $text_color);
Now that will show the following text on the image...
code: Rumble pit: 1
Team skirmish: 5
|
|
01-21-2005 09:29 PM |
|
|
Pages: (4):
« First
«
1
[ 2 ]
3
4
»
Last »
|
|
|