note 61766 deleted from ref.image by nlopess

From: Date: Sat, 11 Feb 2006 20:08:19 +0000
Subject: note 61766 deleted from ref.image by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-103524@lists.php.net to get a copy of this message
Note Submitter: sean at dioxide dot be ---- I have a script that generates an image for me to use on forums and the like which has information from a XML feed that I parse to get information to write on the sig. However I need to cache some images (about 3-5 minute cache) to prevent my bandwidth being zapped by it. Here is the code: <?php if($data = file_get_contents("http://bot2k3.net/api/mirrors.php?full")) { if($xml = xml_parser_create()) { /* Use XML parser */ if(xml_parse_into_struct($xml, $data, $values, $indexes)) { $online = $values[$indexes["ONLINE" ][0]]["value"]; $mirrors = $values[$indexes["MIRRORS"][0]]["value"]; $users = $values[$indexes["USERS"][0]]["value"]; $uptime = $values[$indexes["UPTIME"][$k ]]["value"]; /* Loop over indexes later */ $monline = "Mirrors online: " . $online . "/" . $mirrors; $uadded = "Total users since launch: " . $users; } } } else { echo "couldnt retrieve page"; } // declare variables $width = 600; $height = 120; $fontpath = "frizqt.ttf"; $addfont = "frizqt.ttf"; $bgjpg = "background.jpg"; $iconpng = "http://bot2k3.net/images/avatars/Current.imk.png"; // create a new image and allocate the colors we will use $im = imagecreatetruecolor($width, $height); $white = imagecolorallocate($im, 255, 255, 255); $fontcolor = imagecolorallocate($im, 15, 15, 15); // fill the canvas with white imagefill($im, 0, 0, $white); // open our background image $bg = imagecreatefromjpeg($bgjpg); // copy enough of the background image onto the canvas so that it is entirely covered // we only want the copied background to have 60% opacity imagecopymerge($im, $bg, 0, 0, 0, 0, $width, $height, 100); // close the background image imagedestroy($bg); // open our icon image $icon = imagecreatefrompng($iconpng); // copy the entire icon image onto our canvas (at the vertical center) imagecopy($im, $icon, 20, $height/2 - imagesy($icon)/2, 0, 0, imagesx($icon), imagesy($icon)); // render the sample text next to the icon imagettftext($im, 14, 0, 40 + imagesx($icon), 25, $fontcolor, $fontpath, "BOT2K3 Stats"); imagettftext($im, 12, 0, 40 + imagesx($icon), 50, $fontcolor, $fontpath, $monline); imagettftext($im, 12, 0, 40 + imagesx($icon), 75, $fontcolor, $fontpath, $uadded); imagettftext($im, 7, 0, 40 + imagesx($icon), 100, $fontcolor, $addfont, $list1 . " " . $list2); imagettftext($im, 5, 0, 420, 115, $fontcolor, $fontpath, "BUILD 2a :: powered by www.bot2k3.net"); // close the icon image imagedestroy($icon); // draw a border around the image imagerectangle($im, 0, 0, $width-1, $height-1, $fontcolor); imageinterlace($im, 1); // we are done; output the image as a PNG header("Content-Type: image/png"); imagepng($im); imagedestroy($im); ?> If someone would like to help me implement a cache for this script, please contact me on my email or on msn (same address) Thanks :)

« previous php.notes (#103524) next »