Log in

View Full Version : creating several dynamic images with php



nicmo
04-16-2009, 05:02 PM
hello,

i am looking for a tutorial/resource/script that would help me create several dynamic images with mysql information on them in php.

The purpose is to allow members of an online browser game to show their "stats" to other people on forums, etc by the use of signatures.

Ive found many tutorials regarding GD but they are all used for just one image or temporary image. I wanted to create an image for each member and update it with is stats every X hours.

If anyone know anything about this, please let me know, cheers!

nicmo
04-19-2009, 06:50 PM
still looking, cheers!

sxRossi
04-21-2009, 07:13 AM
I did this in the way 'The script is the image'

declare the script-output as image ( png is my favorite)
(MakePNGCacheFileName is a routine wich you must provide :) )



$guid="a fantasy string" ;


header("Content-type: image/png");

$PNGfile=MakePNGCacheFileName($guid.$theme."X".$sizeid."X") ;

header('Content-Disposition: inline; filename="'.basename($PNGfile).'"') ;
header("Last-Modified: ".gmdate("D, d M Y 00:00:00")." GMT");
header("Expires: ".gmdate("D, d M Y 00:01:00", time()+86400)." GMT") ;



this is followed by a caching instruction to control serverload




if(true) //Cache ON/OFF Control
{
if (is_file($PNGfile))
{
readfile($PNGfile);
return(0);
}
}




process the image through the GD-Lib
and send the image out / save a copy for the cache



imagepng($image);
imagepng($image,$PNGfile);
imagedestroy($image);



If you use time-functions in your MakePNGCacheFileName you can control
how often the image is calculated.

The values of $theme and $sizeid wich are passed to my MakePNGCacheFileName function are results of url-parameters wich in your case could be the playername.

Note that the directory for the image output must be write enabled for the webserver process.

In my case the cleaning of old images is done by a cron-job

The script is then embedded in the (HTML) <img> tag: <img src="myscript.php" ...

Good luck