I was developed it for my site and i want to give this mod to all...
Description:
This mod will autamatically apply watermark on all your images. It may be show at your desicion. This MOD will not affect on image quality!
Installation Level: Easy
Installation Time: 5 Minutes
New files:
_watermark
watermark.png
.htaccess
1. Create a _watermark.php and put this code in this file:
<?
waterMark($_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'], "watermark.png", "top=20,center=");
function waterMark($original, $watermark, $placement = 'middle=5, center=50', $destination = null) {
$original = urldecode($original);
$info_o = @getImageSize($original);
if (!$info_o)
return false;
$info_w = @getImageSize($watermark);
if (!$info_w)
return false;
list ($vertical, $horizontal) = split(',', $placement,2);
list($vertical, $sy) = split('=', trim($vertical),2);
list($horizontal, $sx) = split('=', trim($horizontal),2);
switch (trim($vertical)) {
case 'bottom':
$y = $info_o[1] - $info_w[1] - (int)$sy;
break;
case 'middle':
$y = ceil($info_o[1]/2) - ceil($info_w[1]/2) + (int)$sy;
break;
default:
$y = (int)$sy;
break;
}
switch (trim($horizontal)) {
case 'right':
$x = $info_o[0] - $info_w[0] - (int)$sx;
break;
case 'center':
$x = ceil($info_o[0]/2) - ceil($info_w[0]/2) + (int)$sx;
break;
default:
$x = (int)$sx;
break;
}
header("Content-Type: ".$info_o['mime']);
$original = @imageCreateFromString(file_get_contents($original));
$watermark = @imageCreateFromString(file_get_contents($watermark));
$out = imageCreateTrueColor($info_o[0],$info_o[1]);
imageCopy($out, $original, 0, 0, 0, 0, $info_o[0], $info_o[1]);
if( ($info_o[0] > 250) && ($info_o[1] > 250) )
{
imageCopy($out, $watermark, $x, $y, 0, 0, $info_w[0], $info_w[1]);
}
switch ($info_o[2]) {
case 1:
imageGIF($out);
break;
case 2:
imageJPEG($out, NULL, 100);
break;
case 3:
imagePNG($out);
break;
}
imageDestroy($out);
imageDestroy($original);
imageDestroy($watermark);
return true;
}
?>
2. Create a picture, which you want to show as watermark with name watermark.png
3. Create directory with name watermark and put this 2 files into (_watermark.php and watermark.png) and upload this to the root directory
4. Create a .htaccess file with this code and put this file to data/:
In case if you have a validation on you site put this file to data/tmp_media,
In case if you have a straight upload on you site put this file to data/media/(category which you want watermarked),
Upload this file to all directories (data/media/[all directories] and tmp_media) if you want watermark all you images from database
DirectoryIndex index.php
<FilesMatch "\.(gif|jpg|png|JPG)$">
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ /watermark/_watermark.php [T=application/x-httpd-php,L,QSA]
</FilesMatch>
DEMO: