4images Forum & Community
4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: MrAndrew on May 26, 2010, 11:50:31 AM
-
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:
-
Added to:
http://www.4homepages.de/forum/index.php?topic=24888.msg136127#msg136127
THX
But all Pictures and Icons have a watermark, not only the Details-Images
-
Hmmm, starnge!
Ae you sure that you upload .htaccess only in tmb_media or media???
-
Thanks for the mod, I'd bet Sumale.nin added code into .htaccess in root, not in data folder :)
-
Yes :D
Sorry! But now is perfect!!
-
if i'm using this,
i just can see the alt tag,
no image, no watermark
any suggestions?
-
Hello and welcome to 4images forum.
If you can, see if anything in server's error logs
Also, just in case replace <? at the beginning of _watermark.php with:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
then try open an image directly, see if anything shows.
-
Not Found
The requested document was not found on this server.
Web Server at *.de
but the image exists at the ftp server...
a configuration problem?
when i delete the htacces file i can see the image normaly
-
Make sure the path to the _watermark.php is correct in this line:
RewriteRule ^(.*)$ /watermark/_watermark.php [T=application/x-httpd-php,L,QSA]
For example if your web root located at this local path:
/home/username/htdocs/
and your 4images at this:
/home/username/htdocs/gallery/
then the path to the _watermark.php should be like this:
/home/username/htdocs/gallery/watermark/_watermark.php
or like this:
/gallery/watermark/_watermark.php
-
nice mod, but how to change the location of the watermark to the bottom right?
-
Welcome to 4images forum.
Replace waterMark($_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'], "watermark.png", "top=20,center=");
with:waterMark($_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'], "watermark.png", "bottom=20,center=");
-
thank you, now i know were too look. Adapted it to go to the bottom right.
-
2. Create a picture, which you want to show as watermark with name watermark.php
... this is incorrect and should mean correct ...
2. Create a picture, which you want to show as watermark with name watermark.png
-
Hallo,
Wenn ich den Mod installiere, werden in meiner Galerie nur mehr die roten Kreuze statt Bilder angezeigt.
Was mache ich da falsch?
Versteh auch nicht ganz welches image ich da erzeugen soll.
-
Hi,
n1 and easy idea for watermarking without changing 4I code :thumbup: but...
howto handle different image sizes?
It seems the script doesn't fit the watermark to image size...
Looks strange if your watermark was made for example
1024x768 but is displayed with a 100x100 image.
Can someone improve this?
Greetz X23
-
I've installed this MOD http://www.4homepages.de/forum/index.php?topic=27311.0
And i want to make option on uploadform page to add or not to add watermark.
Could you halp me?