Hi,
I have an image carousel with a number of images that are going to change fairly often, The images in teh carousel have a nice little frame round them but are used elsewhere on the site without the frame so I wrote a php script to take the jpg image add the frame and then send the image to the browser. So as the carousel cycles roun new images are added to the queue. Used jQuery and it works very well except it could be a bit quicker and wondered if it instead of generating the framed image each time I saved the image to file and then loaded in the framed imaged if it existed.
<?php
$picky = $_GET['picky'];
if (exists("../images/acts/".$picky."plusframe.png") && (filemtime("../images/acts/".$picky."plusframe.png") > filemtime("../images/acts/".$picky.".jpg"))){
$image = file_get_contents("../images/acts/".$picky."plusframe.png");
header("Content-type: image/png");
echo $image;
}else{
$srcImage = imagecreatefromjpeg("../images/acts/".$picky.".jpg");
$srcWidth = imagesx($srcImage);
$srcHeight = imagesy($srcImage);
$destWidth = 156;
$destHeight = 146;
$destImage = imagecreatetruecolor($destWidth, $destHeight);
imagesavealpha($destImage, true);
$trans_colour = imagecolorallocatealpha($destImage, 0, 0, 0, 127);
imagefill($destImage, 0, 0, $trans_colour);
imagecopyresampled($destImage, $srcImage, 6, 6, 0, 0, 144, 134, $srcWidth, $srcHeight);
$srcImage = imagecreatefrompng("../images/general/smallscreen7.png");
imagecopymerge($destImage,$srcImage,0,0,0,0,156,146,100);
$srcImage = imagecreatefrompng("../images/general/shadow.png");
imagecopymerge($destImage,$srcImage,0,0,0,0,156,146,15);
header("Content-type: image/png");
imagepng($destImage);
imagepng($destImage,"../images/acts/".$picky."plusframe.png");
imagedestroy($destImage);
imagedestroy($srcImage);
}
?>
The second half of the code else{...} works fine, including generating the image and writing it to disk, but the first bit, before the else, which checks for the file and its age, and if it exists loads it into the browser doesn't work, all I get is empty place holders.
Thanks
Paul