SRL Archive - General

Get an image banked?


Raskolnikov

2008-01-13 12:55:33

I am trying to make an image that will show how many randoms your script has encountered. I have a problem though. How will I bank the image so that it will keep updating?

Edit: I mean, how will I save the image so that not only the image is just there but I want it to keep updating with new info? Do I do an unending loop?

mastaraymond

2008-01-13 13:15:54

What language are you programming in?

Raskolnikov

2008-01-13 13:47:43

Php

XcanadamanX

2008-01-13 17:08:44

you have to make a dynamic image. you have to use the GD library and mysql. i figure you know that. this is the way i did it:

[PHP]$nav = $_SERVER["REQUEST_URI"];
$script = $_SERVER["SCRIPT_NAME"];
$nav = ereg_replace("^$script", "", $nav);
$nav = str_replace("%20"," ",$nav);
$vars = explode("/", $nav);
$ID = strtolower($vars[1]);[/PHP]

so when you go say my site: www.xcanadamanx.phpnet.us/stats/statssigs.php/1.png it will read the 1. the $ID will be 1. and then you just do a mysql query and find the id 1 and get the infromation you need and then create the image.


[PHP]
imagettftext($im,8.0,0,47,63,$black,$font,$Time);
imagettftext($im,8.0,0,46,61,$white,$font,$Time);
imagettftext($im,8.0,0,47,86,$black,$font,$OldB);
imagettftext($im,8.0,0,46,84,$white,$font,$OldB);
imagettftext($im,8.0,0,50,109,$black,$font,$OldC);
imagettftext($im,8.0,0,49,107,$white,$font,$OldC);
imagettftext($im,8.0,0,154,86,$black,$font,$OldE);
imagettftext($im,8.0,0,153,84,$white,$font,$OldE);
imagettftext($im,8.0,0,168,109,$black,$font,$OldLe);
imagettftext($im,8.0,0,167,107,$white,$font,$OldLe);
imagettftext($im,8.0,0,7,128,$white,$font,$User);
header("Content-type: image/png");
imagepng($im);
imageDestroy($im);[/PHP]

hope this helps.

Raskolnikov

2008-01-14 18:43:12

But I mean how do I get the script to automatically save the image?

XcanadamanX

2008-01-17 21:36:42

[php]imagepng($im,file);[/php]

im guessing you mean this?saves the picture to file

Daniel

2008-01-18 02:16:13

From: XcanadamanX
[php]imagepng($im,file);[/php]

im guessing you mean this?saves the picture to file

This is also a thing that has puzzled me.

How can a picture change? Because i am very interested in learning this too.

XcanadamanX

2008-01-18 07:58:05

how can it change? maybe i dont understand because i just got up like 5 mins ago. could you rephrase it? do you mean how can you make it change or how does it change.

Raskolnikov

2008-01-18 18:22:22

I have a php 5 book and it has an appendix. The appendix holds most of the functions in php.
[PHP]imagepng($im);[/PHP]

You see that it only has one parameter. I don't think you can save for some reason. Maybe there is a way to do it by accessing photobucket and doing it that way?

XcanadamanX

2008-01-18 20:35:28

go to php.net and look up imagepng

heres the link: http://ca3.php.net/manual/en/function.imagepng.php

Raskolnikov

2008-01-24 00:15:43

Oh, sorry. My book isn't that in depth :D. Hmm, still, something's wrong. I am using get and post but it isn't working. I have one webpage that has a form, then it sends to the other page. For some reason it isn't working. I tried the trim function too… Like I would use a get variable to put in the script id. Can someone give me the code to do that, soz, I'm a noob :(

Cut em2 it

XcanadamanX

2008-01-24 08:11:33

Get and Post? show me the code. ill see what i can come up with.

Raskolnikov

2008-01-24 21:35:20

MM, let me get it.

Edit: And I've tried both get and post…

[php]<?
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
header('Content-type: image/png');
$that = $_GET["Script id"];
$that = ltrim($that);
$wherescript = "http://stats.srl-forums.com/index.php?action=view_script&id=".that;
$curlclient = curl_init($wherescript);
curl_setopt($curlclient, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($curlclient);
$logins = get_string_between($data, 'Logged In : <strong>', '</strong>');
$frogs = get_string_between($data, 'Frogs : <strong>', '</strong>');
if ($frogs == "") {
$frogs = "0";
}
$boxes = get_string_between($data, 'Boxes : <strong>', '</strong>');
if ($boxes == "") {
$boxes = "0";
}
$oldmen = get_string_between($data, 'Oldmen : <strong>', '</strong>');
if ($oldmen == " ") {
$oldmen = "0";
}
$worked = get_string_between($data, 'Worked : <strong>', '</strong>');
$name = get_string_between($data, 'Total Randoms Solved by ', '</td>');
$lastconnection = get_string_between($data, 'Last Connection : <strong>', '</strong>');
$im = imagecreatefrompng('http://i237.photobucket.com/albums/ff60/cut_em2/thing-1.png');
$color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 55, 6, $name, $color);
imagestring($im, 4, 11, 89, "Solved or encountered ".$oldmen." oldmen.", $color);
imagestring($im, 4, 11, 49, "Logged in ".$logins." times.", $color);
imagestring($im, 4, 11, 69, "Solved ".$boxes." boxes.", $color);
imagestring($im, 4, 11, 109, "Solved ".$frogs." frogs.", $color);
imagestring($im, 4, 11, 129, "Worked for".$worked, $color);
imagestring($im, 4, 11, 149, "Last con.: ".$lastconnection, $color);
imagepng($im);
imagedestroy($im);
echo("Your image has been saved at http://cutfiles.mygamesonline.org/". $that . ".png");
?>
[/php]

This is the non-form one.

Here is the form one:

[php]<form action="curltest.php" method="get">
Script Id: <input type="text" name="Script id" />
<input type="submit" />
</form>
[/php]

Thanks,
Cut em2 it

XcanadamanX

2008-01-25 14:00:25

first thing i saw:
[php]$wherescript = "http://stats.srl-forums.com/index.php?action=view_script&id=".that;[/php]
shouldnt it be
[php]$wherescript = "http://stats.srl-forums.com/index.php?action=view_script&id=".$that;[/php]

and
[php]imagepng($im);[/php]
should be
[php]imagepng($im,"http://cutfiles.mygamesonline.org/". $that . ".png");[/php]

Raskolnikov

2008-01-25 19:25:19

Ahhh, whoops, let me check if it works now.