PHP gd caching an image

This example shows how to display caching of an image.

 
 

Share on Google+Share on Google+

PHP gd caching an image

Ads

This example shows how to display caching of an image.

<?php

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

$filename = date("Y_m_d").".png";

if (is_file($filename)) {

readfile($filename);

exit;

}

$image = imagecreatetruecolor(100,25);

$white = imagecolorallocate($image,255,255,255);

$black = imagecolorallocate($image,0,0,0);

imagefill($image,0,0,$white);

imagerectangle($image,0,0,99,24,$black);

imagestring($image,5,5,5,date("d/m/Y"),$black);

imagepng($image,$filename);

imagepng($image);

imagedestroy($image);

?>

After running the program you will get the following output

Advertisements

Ads

Posted on: November 2, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles