Shoutbox

PHP Images... I can't make one. :( - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: PHP Images... I can't make one. :( (/showthread.php?tid=37177)

PHP Images... I can't make one. :( by Moo on 01-19-2005 at 12:07 AM

Can someone help me make a Halo 2 stat picture? The stats are at http://www.bungie.net/Stats/PlayerStats.aspx?player=guyguyme2003 .
I would like to have it look like http://guillaumelforum.theglassprison.net/halo2/s...rName=guyguyme2003 and I would like to see the clan stats too (link is on my stats page... take it from there, as it will change)

Thanks!


RE: PHP Images... I can't make one. :( by fluffy_lobster on 01-19-2005 at 04:51 PM

Link of the day: http://php.net/image

Look at a basic function that you're likely to need such as imagecreate() and there are loads of examples that branch out to help you do what you want to do.

Failing that plenty of tutorials exist.  I suggest webmonkey


RE: PHP Images... I can't make one. :( by -dt- on 01-19-2005 at 05:32 PM

after you can create an image with php + write text on it you will need to download the site you wish to parse into a varible a common (and semi good) way to do it is like

code:
<?
$handle = fopen("http://www.bungie.net/Stats/PlayerStats.aspx?player=guyguyme2003", "rb");
$contents = '';
while (!feof($handle)) {
  $contents .= fread($handle, 8192);
}
fclose($handle);


?>
(you can read about
fopen here
fread here
fclose here
)
then $contents will hold the entire stat page which you will have to  parse and cache then print onto the image.

It shouldn't be too hard if you need any help pm me  something :P
RE: PHP Images... I can't make one. :( by Moo on 01-19-2005 at 09:06 PM

Man! I suck! I cant get the image to work... all i see is a blank page!


RE: PHP Images... I can't make one. :( by WDZ on 01-19-2005 at 09:12 PM

quote:
Originally posted by Guillaume
Man! I suck! I cant get the image to work... all i see is a blank page!
Well, what are you expecting to see? Did you make a script?
RE: PHP Images... I can't make one. :( by Moo on 01-19-2005 at 09:19 PM

I put

code:
<?php
header("Content-type: image/png");
$im = @imagecreate(100, 50)
   or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  "This will soon be replaced with something else.", $text_color);
imagepng($im);
imagedestroy($im);
?>

RE: PHP Images... I can't make one. :( by WDZ on 01-19-2005 at 09:34 PM

* WDZ saves the file on his local server and tries it

It works. :-/ The text is cut off because of the small image width, but other than that, it's fine.

Are you trying it on a server that supports PHP & GD and doesn't have any dodgy stuff like forced advertisements?


RE: PHP Images... I can't make one. :( by Moo on 01-19-2005 at 09:36 PM

i duno if GD is there...
EDIT: For some reason, PHP doesn't work anymore.


RE: PHP Images... I can't make one. :( by WDZ on 01-19-2005 at 09:42 PM

Hmm... well, you should move the header() line so it's right above the imagepng() line. If the script is outputting any text error messages, the browser might not display them because it's expecting a PNG image. Just for clarity, here's the modified code:

code:
<?php
$im = @imagecreate(100, 50)
   or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  "This will soon be replaced with something else.", $text_color);
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>

RE: RE: PHP Images... I can't make one. :( by Moo on 01-19-2005 at 09:51 PM

quote:
Originally posted by WDZ
Hmm... well, you should move the header() line so it's right above the imagepng() line. If the script is outputting any text error messages, the browser might not display them because it's expecting a PNG image. Just for clarity, here's the modified code:

code:
<?php
$im = @imagecreate(100, 50)
   or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  "This will soon be replaced with something else.", $text_color);
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>

Still a blank page... phpinfo() displays a blank page also.
RE: PHP Images... I can't make one. :( by Moo on 01-19-2005 at 09:59 PM

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 :
[Image: sig/]
I am trying to take out a part of the cache txt i have.


RE: PHP Images... I can't make one. :( by Moo on 01-19-2005 at 10:37 PM

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?


RE: PHP Images... I can't make one. :( by -dt- on 01-20-2005 at 07:04 AM

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.

RE: PHP Images... I can't make one. :( by Moo on 01-20-2005 at 10:24 PM

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
[Image: index.php]

PS: that was to see if i could make it work.
RE: PHP Images... I can't make one. :( by WDZ on 01-21-2005 at 04:29 AM

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.
RE: RE: PHP Images... I can't make one. :( by -dt- on 01-21-2005 at 04:36 AM

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
[Image: index.php]

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 :(
RE: PHP Images... I can't make one. :( by Moo on 01-21-2005 at 08:30 PM

-dt-, I tried your script and I got:
[Image: index2.php]

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?
RE: PHP Images... I can't make one. :( by segosa on 01-21-2005 at 09:02 PM

quote:
Originally posted by Guillaume

And WDZ, How do you add line breaks between strings?

\n
RE: PHP Images... I can't make one. :( by Moo on 01-21-2005 at 09:08 PM

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?
RE: PHP Images... I can't make one. :( by WDZ on 01-21-2005 at 09:29 PM

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. (y)

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

RE: PHP Images... I can't make one. :( by Moo on 01-21-2005 at 09:38 PM

Sweet! I have numbers!
ill just make a background and align the numbers.


RE: PHP Images... I can't make one. :( by Moo on 01-21-2005 at 09:56 PM

:/

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 = @imagecreatefrompng("http://guillaumelforum.theglassprison.net/Halo%202%20Stats_files/stats1.png");
$text_color = imagecolorallocate($im, 0, 0, 0);
$line = 10;
imagestring($im, 12, 5, $line, $rumble_pit, $text_color);
$line = $line + 15;
imagestring($im, 12, 5, $line, $team_skirmish, $text_color);
$line = $line + 15;
imagestring($im, 12, 5, $line, $head_to_head, $text_color);
$line = $line + 15;
imagestring($im, 12, 5, $line, $big_team_battle, $text_color);
$line = $line + 15;
imagestring($im, 12, 5, $line, $team_slayer, $text_color);

imagepng($im);
imagedestroy($im);

?>

gave me
quote:
Originally posted by Error
<br />
<b>Warning</b>:  imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/theglas/public_html/guillaumelforum/halo2/index.php</b> on line <b>30</b><br />
<br />
<b>Warning</b>:  imagestring(): supplied argument is not a valid Image resource in <b>/home/theglas/public_html/guillaumelforum/halo2/index.php</b> on line <b>32</b><br />
<br />
<b>Warning</b>:  imagestring(): supplied argument is not a valid Image resource in <b>/home/theglas/public_html/guillaumelforum/halo2/index.php</b> on line <b>34</b><br />
<br />
<b>Warning</b>:  imagestring(): supplied argument is not a valid Image resource in <b>/home/theglas/public_html/guillaumelforum/halo2/index.php</b> on line <b>36</b><br />
<br />
<b>Warning</b>:  imagestring(): supplied argument is not a valid Image resource in <b>/home/theglas/public_html/guillaumelforum/halo2/index.php</b> on line <b>38</b><br />
<br />
<b>Warning</b>:  imagestring(): supplied argument is not a valid Image resource in <b>/home/theglas/public_html/guillaumelforum/halo2/index.php</b> on line <b>40</b><br />
<br />
<b>Warning</b>:  imagepng(): supplied argument is not a valid Image resource in <b>/home/theglas/public_html/guillaumelforum/halo2/index.php</b> on line <b>42</b><br />
<br />
<b>Warning</b>:  imagedestroy(): supplied argument is not a valid Image resource in <b>/home/theglas/public_html/guillaumelforum/halo2/index.php</b> on line <b>43</b><br />



RE: PHP Images... I can't make one. :( by WDZ on 01-21-2005 at 10:01 PM

Well, the URL http://guillaumelforum.theglassprison.net/Halo%20...s_files/stats1.png doesn't work for me, and it's not necessary to use a URL anyway. You should have the image on the same server as the script and use a relative path, such as "Halo 2 Stats_files/stats1.png" or just "stats1.png" if the image and script are in the same folder.


RE: PHP Images... I can't make one. :( by Moo on 01-21-2005 at 10:05 PM

oops.. wrong url... wrong format... :* http://guillaumelforum.theglassprison.net/halo2/H...s_files/stats1.jpg


RE: PHP Images... I can't make one. :( by Moo on 01-21-2005 at 10:07 PM

Why wont this work?

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 = @imagecreatefromjpg("http://guillaumelforum.theglassprison.net/halo2/Halo%202%20Stats_files/stats1.jpg");
$text_color = imagecolorallocate($im, 0, 0, 0);
$line = 10;
imagestring($im, 12, 5, $line, $rumble_pit, $text_color);
$line = $line + 15;
imagestring($im, 12, 5, $line, $team_skirmish, $text_color);
$line = $line + 15;
imagestring($im, 12, 5, $line, $head_to_head, $text_color);
$line = $line + 15;
imagestring($im, 12, 5, $line, $big_team_battle, $text_color);
$line = $line + 15;
imagestring($im, 12, 5, $line, $team_slayer, $text_color);

imagepng($im);
imagedestroy($im);

?>


RE: PHP Images... I can't make one. :( by WDZ on 01-21-2005 at 10:12 PM

imagecreatefromjpg should be imagecreatefromjpeg (add an e)

Also, your text color should be white (255,255,255) instead of black since your background is dark.

The script works fine for me after those 2 changes. Needs some tweaking, but at least it's working...


RE: PHP Images... I can't make one. :( by Moo on 01-21-2005 at 10:13 PM

quote:
Originally posted by WDZ
imagecreatefromjpg should be imagecreatefromjpeg (add an e)

Also, your text color should be white (255,255,255) instead of black since your background is dark.

The script works fine for me after those 2 changes. Needs some tweaking, but at least it's working...
Sweet
* Moo fixes

RE: PHP Images... I can't make one. :( by Moo on 01-21-2005 at 10:43 PM

using

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 = @imagecreatefromjpeg("http://guillaumelforum.theglassprison.net/halo2/Halo%202%20Stats_files/statsforimg.jpg");
$text_color = imagecolorallocate($im, 255, 255, 255);
$line = 42;
imagestring($im, 1, 102, $line, $rumble_pit, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $team_skirmish, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $head_to_head, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $big_team_battle, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $team_slayer, $text_color);
imagepng($im);
imagedestroy($im);

?>

I only get 3 values :s
[Image: index.php]
RE: PHP Images... I can't make one. :( by WDZ on 01-21-2005 at 10:59 PM

Hmm... it looks like the stats page on bungie.net has changed... :^)

"Head To Head - No Games Played" messes up the script. That sucks... :p

I don't see an easy way to fix the problem... the script would require some changes, and I don't have time to help with that right now.


RE: PHP Images... I can't make one. :( by Moo on 01-21-2005 at 11:03 PM

quote:
Originally posted by WDZ
Hmm... it looks like the stats page on bungie.net has changed... :^)

"Head To Head - No Games Played" messes up the script. That sucks... :p

I don't see an easy way to fix the problem... the script would require some changes, and I don't have time to help with that right now.
I'll try and figure it out.
RE: PHP Images... I can't make one. :( by Moo on 01-22-2005 at 12:35 AM

I found a way to put the values at the right place... instead of $line, I put the real value.


RE: PHP Images... I can't make one. :( by -dt- on 01-22-2005 at 11:11 AM

quote:
Originally posted by Guillaume
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 = @imagecreatefromjpeg("http://guillaumelforum.theglassprison.net/halo2/Halo%202%20Stats_files/statsforimg.jpg");
$text_color = imagecolorallocate($im, 255, 255, 255);
$line = 42;
imagestring($im, 1, 102, $line, $rumble_pit, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $team_skirmish, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $head_to_head, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $big_team_battle, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $team_slayer, $text_color);
imagepng($im);
imagedestroy($im);

?>




err is that still how to script works? is there no caching? you know everytime that script is loaded it downloads the whole stats page ?

you need to set up a caching system how i would do it is check if the cache exists then if it does i would check the  current time (time() ) agiesnt the file time of the cache file ( filemtime($cache) )
if the cache is past 30min or so (the time() produces funky unix time use something like $blah = time() -  filemtime($cache); to get seconds scince last update )

then if its like 30min past last update download the stats again and write it to a file (use fwrite) .

If its not 30min past use fread to read the cache file then load it into your script and use that for stats insted.


post if you dont quite get me and ill post some sample code :P but look up some of the terms i used like fwrite and search it on http://php.net

but atleast try to make some of the code :)
or post here for help
RE: PHP Images... I can't make one. :( by Moo on 01-22-2005 at 03:48 PM

quote:
Originally posted by -dt-
quote:
Originally posted by Guillaume
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 = @imagecreatefromjpeg("http://guillaumelforum.theglassprison.net/halo2/Halo%202%20Stats_files/statsforimg.jpg");
$text_color = imagecolorallocate($im, 255, 255, 255);
$line = 42;
imagestring($im, 1, 102, $line, $rumble_pit, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $team_skirmish, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $head_to_head, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $big_team_battle, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $team_slayer, $text_color);
imagepng($im);
imagedestroy($im);

?>




err is that still how to script works? is there no caching? you know everytime that script is loaded it downloads the whole stats page ?

you need to set up a caching system how i would do it is check if the cache exists then if it does i would check the  current time (time() ) agiesnt the file time of the cache file ( filemtime($cache) )
if the cache is past 30min or so (the time() produces funky unix time use something like $blah = time() -  filemtime($cache); to get seconds scince last update )

then if its like 30min past last update download the stats again and write it to a file (use fwrite) .

If its not 30min past use fread to read the cache file then load it into your script and use that for stats insted.


post if you dont quite get me and ill post some sample code :P but look up some of the terms i used like fwrite and search it on http://php.net

but atleast try to make some of the code :)
or post here for help
I'll give it a shot.

RE: PHP Images... I can't make one. :( by Moo on 01-22-2005 at 04:25 PM

Allright! I got a good one!