View Single Post
Old 02-07-2010, 09:24 AM  
SmellyNose
Confirmed User
 
SmellyNose's Avatar
 
Industry Role:
Join Date: Aug 2009
Location: me at smellynose.com
Posts: 206
Or if your site is in PHP you could do something like this:

Code:
$base_dir = getcwd(); // meh
$f_file = $base_dir . $file;
$w_file = $base_dir . "/watermarked/".$file;
$water_file = $base_dir.'watermark.png';

$file = $_GET['file']; // Add security measures
header("Content-Type: image/jpeg");

if(!file_exists($f_file)) {
   readfile($base_dir . "invalid_image.jpg");
   exit;
}

if(!file_exists($w_file)) {
   readfile($w_dir);
   exit;
}

//Borrowed from http://articles.sitepoint.com/article/watermark-images-php as this is in a quick reply box so won't be writing new code as this is an example/idea :P

$watermark = imagecreatefrompng($water_file);
$watermark_width = imagesx($watermark);  
$watermark_height = imagesy($watermark);  
$image = imagecreatetruecolor($watermark_width, $watermark_height);  
$image = imagecreatefromjpeg($f_file);
$size = getimagesize($f_file);  
$dest_x = $size[0] - $watermark_width - 5;  
$dest_y = $size[1] - $watermark_height - 5;  
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);  
imagejpeg($image);  
imagedestroy($image);  
imagedestroy($watermark);

//Some code here to put the watermarked image into $base_dir . 'watermarked/'.$file so the image is cached for next time
SmellyNose is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote