Return to Snippet

Revision: 69347
at June 3, 2015 07:51 by bts4


Initial Code
<?php  
//ini_set('max_execution_time', 300);
header('content-type: image/jpeg');  
header('Cache-control: max-age='.(60*60*24*365));
header('Expires: '.gmdate(DATE_RFC1123,time()+60*60*24*365));
$cache_file = "./img/". hash('md5', $_GET['src']).".jpg";

if (file_exists($cache_file)) { //CACHE HIT
	header('Last-Modified: '.gmdate(DATE_RFC1123,filemtime($cache_file)));
	echo(file_get_contents($cache_file));

} else { //CACHE MISS	

	$watermark = imagecreatefrompng("watermarkd.png");  
	$watermark_width = imagesx($watermark);  
	$watermark_height = imagesy($watermark);
	$image = imagecreatetruecolor($watermark_width, $watermark_height);  
	$image = imagecreatefromjpeg($_GET['src']);  
	$size = getimagesize($_GET['src']); 
	$dest_x = $size[0] - $watermark_width - 5;  
	$dest_y = $size[1] - $watermark_height - 5;  
	imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);  
	imageinterlace($image, true);
	imagejpeg($image,$cache_file,100);   
	echo(file_get_contents($cache_file));
	imagedestroy($watermark);
	imagedestroy($image);
}
exit();
?>

Initial URL


Initial Description
Image Watermarker with file system cache

Initial Title
PHP image watermarker with file system cache

Initial Tags


Initial Language
PHP