PHP gd caching an image


 

PHP gd caching an image

This example shows how to display caching of an image.

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

Ads