4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: batu544 on November 27, 2008, 09:06:57 AM

Title: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on November 27, 2008, 09:06:57 AM
Hi all,

here is a way to watermark the images on-fly instead of actually watermarking the images.. When the user will try to download, the original image will be downloaded...  :D


1. Upload the following file as watermark.php

Code: [Select]
<?php

header
('content-type: image/jpeg');
$img $_GET['img'];
$watermark imagecreatefrompng('watermark.png');

$watermark_width imagesx($watermark);
$watermark_height imagesy($watermark);
$image imagecreatetruecolor($watermark_width$watermark_height);
$image imagecreatefromjpeg("$img");
$size getimagesize("$img");
$dest_x $size[0] - $watermark_width 5;
$dest_y $size[1] - $watermark_height 5;

imagecopymerge($image$watermark$dest_x$dest_y00$watermark_width$watermark_height100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);

?>


2. Open jpg.html from your template/xxx/media folder and change
Code: [Select]
<img src="{media_src}" border="1" alt="{image_name}"{width_height} /><br />
to

Code: [Select]
<img src="./watermark.php?img={media_src}" border="1" alt="{image_name}"{width_height} /><br />


3. Upload your watermark.png picture.. to root folder.

4. Now all set .. you can see the watermarked images ..   :D


Demo : bhwallpapers (http://www.bhwallpapers.com/go)  ( You need to click on the image to see the actual watermarked image )
Thanks

Edit: Sorry, now the demo is not available due to the changes in the website design.. :(
Title: Re: On-fly image annotation ( watermark).
Post by: mawenzi on December 06, 2008, 07:58:31 PM
Hi batu544 ...

... thanks for sharing this watermark mod ... it works perfectly ...
... I moved the thread to Mods & Plugins (Releases & Support) ...
... only three hints for other users ...

1. if you want to show the watermark in the middle of your image, use this in your watermark.php ...
Code: [Select]
$dest_x = $size[0]/2 - $watermark_width/2 ;
$dest_y = $size[1]/2 - $watermark_height/2;

2. if you want to show the watermark only to guests (non registered users), use this in your jpg.html ...
Code: [Select]
{if user_loggedin}<img src="{media_src}" border="1" alt="{image_name}"{width_height} /><br />{endif user_loggedin}
{if user_loggedout}<img src="./watermark.php?img={media_src}" border="1" alt="{image_name}"{width_height} /><br />{endif user_loggedout}

3. perhaps you should use a transparent gif-watermark image ...
... because IE6 can not right show transparent png-images ...
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on December 07, 2008, 01:51:54 PM
Thanks mawenzi !! for moving this to Mods & Plugins (Releases & Support) section.

Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Sunny C. on December 07, 2008, 04:21:19 PM
Very Very Very Nice :D
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: mawenzi on December 07, 2008, 05:28:02 PM
3. perhaps you should use a transparent gif-watermark image ...
... because IE6 can not right show transparent png-images ...

... just tested in IE6 ... and it works perfektly with png-watermark image ...
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: kai on December 08, 2008, 08:29:43 PM
Great! Thank you!
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Pedrocas on February 01, 2009, 07:14:13 PM
This seems great!
I have 2 questions:

- Where do I upload the watermark.php file?
- How will the already added pictures been show?

Thanks,
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on February 02, 2009, 05:20:02 AM
HI,

1.      Upload it in root folder. ( where you have installed your 4image).
2.      It will not really add any watermark to the images. So, It will also work in the same way for the wallpapers which are already added.

Thanks

Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Pedrocas on February 02, 2009, 10:46:08 AM
Thanks for the reply.
That's precisely my problem, because all the 3500 images that I have are already tagged.
Any possible solution for this?
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on February 02, 2009, 01:24:33 PM
because all the 3500 images that I have are already tagged.

I didn't get your question .. what do you mean by tagged ??

Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Pedrocas on February 02, 2009, 07:30:52 PM
I mean all my images were marked in photoshop before being uploaded...
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: mawenzi on February 02, 2009, 08:13:47 PM
a hint ... ;)

... the latest script worked on tagged the images ... either PS on your pc or Annotation on the server ...
... but if you have big-images ( in the big-folder ... a MOD by V@no ) on your server for downloading ...
... then you can use Annotation for images on your detail sites ...
... and you can use the original images (tagged by PS) for downloading ...
                                                   
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: cliff on February 03, 2009, 01:24:35 PM
Hallo,

gibt es evtl. eine Möglichkeit das später zu sehende Bild mit der watermark.php auf eine bestimmte Größe zu skalieren. Ich habe zwar gegoogelt, bin aber nicht wirklich weiter gekommen. Gut wäre, wenn das Originalbild auf die spätere Größe skaliert wird und darüber die entsprechende png-Grafik gelegt würde...

Das zu sehende Bild soll für Gäste lediglich 350px breit oder hoch sein... Die watermark.php würde ich dann in watermark1.php umbenennen und für Gäste den Zugriff mit eben dieser php-Datei umsetzen...


-----

is there any option that the new image with the watermark got a fixed size. It would be great if the originall jpeg will be reduced and that new jpeg gets watermarked...
The image in the gallery should have a size of max. 350px (width or heigth)! Than I will change the watermark.php into watermark1.php for viewing the image by guest.

----

Fragende Grüße
cliff
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: mawenzi on February 03, 2009, 04:53:26 PM
... wenn du ein "Medium"-Bild suchst und dein Originalbild z.B. auch für den Download auf deinem Server speichern willst ...
... dann gibt es das hier ...
... [TUT] One Image - Three Sizes ...
... http://www.4homepages.de/forum/index.php?topic=20496.0 ...
... und welchen Annotations-MOD du dann auch nimmst : "Medium"-Bilder sind dann mit Watermark, Originalbilder ohne Watermark ...
... solltest du dich noch anderen Varianten der Bildscallierung umsehen, so sind in dem TUT noch weitere Varianten aufgeführt ...
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: cliff on February 03, 2009, 08:05:03 PM
Hallo Mawenzi,

und danke für die prompte Antwort...

Ich habe ja schon eine Modifikation, so daß sich die Bilder zunächst in das Design einfügen und per Ajax in groß gezeigt werden können. Aber es würde mich schon sehr interessieren, ob man die watermark.php dahingehend ändern könnte, dass zunächst das Originalbild skaliert wird und dann das Wasserzeichen darüber gelegt wird. Ansonsten würde ja auch das Wasserzeichen immens verkleinert werden (analog zur Ursprungsgröße).

Gibt´s da keine Modifikation?

Dankende Grüße
cliff
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: cliff on February 04, 2009, 09:19:17 PM
Ich habe es jetzt dann doch per google hinbekommen... Hier der geänderte php-Code für Interessierte!

Das verkleinerte Bild (Thumbnail) ist in diesem Fall 450px breit und proportional in der Höhe verkleinert.
Code: [Select]
<? 
// Bilddaten feststellen 
  $size=getimagesize($_GET['bild']); 
  $breite=$size[0]; 
  $hoehe=$size[1]; 

  //hier die Breite festlegen 
  $neueBreite=450; 
  $neueHoehe=intval($hoehe*$neueBreite/$breite); 

  if($size[2]==1) { 
  // GIF 
  $altesBild=ImageCreateFromGIF($_GET['bild']); 
  $neuesBild=ImageCreate($neueBreite,$neueHoehe); 
  imagecopyresampled($neuesBild,$altesBild,0,0,0,0,$neueBreite,$neueHoehe,$breite,$hoehe); 
  $watermark = imagecreatefrompng('watermark.png');

$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = $neuesBild;
$size = getimagesize("$neuesBild");


$dest_x = $size[0]/2 - $watermark_width/2 ;
$dest_y = $size[1]/2 - $watermark_height/2;

imagecopymerge($image, $watermark, 0, 0, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
  } 

  elseif($size[2]==2) { 
  // JPG 
  $altesBild=ImageCreateFromJPEG($_GET['bild']); 
  $neuesBild=imagecreatetruecolor($neueBreite,$neueHoehe); 
  imagecopyresampled($neuesBild,$altesBild,0,0,0,0,$neueBreite,$neueHoehe,$breite,$hoehe); 
  $watermark = imagecreatefrompng('watermark.png');

$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = $neuesBild;

$dest_x = $size[0]/2 - $watermark_width/2 ;
$dest_y = $size[1]/2 - $watermark_height/2;

imagecopymerge($image, $watermark, 0, 0, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
  } 

  elseif($size[2]==3) { 
  // PNG 
  $altesBild=ImageCreateFromPNG($_GET['bild']); 
  $neuesBild=imagecreatetruecolor($neueBreite,$neueHoehe); 
  imagecopyresampled($neuesBild,$altesBild,0,0,0,0,$neueBreite,$neueHoehe,$breite,$hoehe); 
  $watermark = imagecreatefrompng('watermark.png');

$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = $neuesBild;

$dest_x = $size[0]/2 - $watermark_width/2 ;
$dest_y = $size[1]/2 - $watermark_height/2;

imagecopymerge($image, $watermark, 0, 0, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
  } 


?>

Hiermit werden auch gifs, pngs und jpegs verkleinert und mit dem Wasserzeichen versehen. Das Originalbild wird erst verkleinert und dann wird das Wasserzeichen darüber gelegt.

Es muss aber auch der Befehl in der detail.html wie folgt geändert werden:
Code: [Select]
<img src="./watermark.php?bild={media_src}" border="0" alt="{image_name}" />

Sofern man verschiedene Bildgrößen haben möchte, z. B. für Gäste kann man alternativ die watermark.php in watermark1.php mit anderen Größenangaben abspeichern. Natürlich wieder den Code in der Detail.html entsprechend ändern...

Ich hoffe, dass ist soweit alles richtig. Bei mir läuft es einwandfrei... Ansonsten: Ich bin kritikfähig!

Gruß
cliff
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: mawenzi on February 04, 2009, 10:23:24 PM
... das sollte theoretisch auch soweit funktionieren ...
... nur das dieses Script ganz schön "serverlastig" ist ...
... denn mit jedem Bildaufruf wird das Bild erst verkleinert, dann "gewassermarkt" und zum Schluß in den Papierkorb gehauen ...
... nichts wird gespeichert, und beim nächsten Bildaufruf erfolgt das gleiche Spiel wieder ...
... und das muss man sich jetzt mal mit z.B. 20 Usern vorstellen, die sich alle gleichzeitig Bilder in der Galerie betrachten ...
... da haben Hoster schon wegen weniger "serverlastigen" Scriptteilen einen Account still gelegt ...
... doch wie gesagt, wenn bei dir alles gut läuft (incl. Hoster) dann ist ja alles bestens ... ;)
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: krazy9 on May 30, 2009, 06:58:59 AM
How can I Add More Extension.
Example: png,gif etc..
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on May 30, 2009, 07:15:53 AM
I am not sure whether this will work or not .. but just try to modify gif.html and png.html etc..etc... just like jpg.html


Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: krazy9 on May 30, 2009, 07:23:48 AM
How Can I Add More Extension in this code.
e.g. png,gif ect.
---------------------------------------
Code: [Select]
<?php
header
('content-type: image/[b]jpeg[/b]');
$img $_GET['img'];
$watermark imagecreatefrompng('logo.png');
$watermark_width imagesx($watermark);
$watermark_height imagesy($watermark);
$image imagecreatetruecolor($watermark_width$watermark_height);
$image imagecreatefrom[b]jpeg[/b]("$img");
$size getimagesize("$img");
$dest_x $size[0] - $watermark_width 5;
$dest_y $size[1] - $watermark_height 730;
imagecopymerge($image$watermark$dest_x$dest_y00$watermark_width$watermark_height100);
image[b]jpeg[/b]($image);
imagedestroy($image);
imagedestroy($watermark);
?>
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Sebas Bonito on August 23, 2009, 08:16:04 PM
A tiny tutorial to make it url-friendly (for google etc.).

OLD Link for Annotation Pic:
Code: [Select]
http://www.yoursite.com/watermark.php?img=.data/media/666/DSC001234.JPG
NEW Link for Annotation Pic:
Code: [Select]
http://www.yoursite.com/photo_666__DSC001234.JPG
...so it looks like a real picture-file, but actually it isn't. But google and visitors don't know it :wink:
...AND: The don't know the real path and link to this image.



1. open .htaccess and find
Code: [Select]
#RewriteBase /add below:
Code: [Select]
RewriteRule ^photo_(.*)__(.*)$ watermark.php?img=./data/media/$1/$2... or create this htaccess (if it doesn't exist).


2. open jpg.html and find
Code: [Select]
<img src="./watermark.php?img={media_src}" border="1" alt="{image_name}"{width_height} /><br />and replace it with:
Code: [Select]
<img src="./photo_{media_src2}__{media_src3}" border="1" alt="{image_name}"{width_height} /><br />

3.1. open functions.php and find
Code: [Select]
$media_src = get_file_path($media_file_name, "media", $cat_id, 0, 1);add below
Code: [Select]
$media_src2 = $cat_id;
$media_src3 = $media_file_name;


3.2 find also in the functions.php the following
Code: [Select]
$site_template->register_vars(array(
      "media_src" => $media_src,
add below
Code: [Select]
 "media_src2" => $media_src2,
 "media_src3" => $media_src3,


...that's all. Have fun!  :D
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on August 26, 2009, 07:24:06 PM
hi..
     I changed as per the above post.. and it started working .. but today .. its not working .  :(   So, I revert back the changes .. I think some issues with rewrite stuffs.

Thanks
batu544
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Sebas Bonito on August 26, 2009, 10:39:23 PM
I guess there could be a problem, when a file has a "__" inside, than the rewrite goes wrong. Change it to 3 "_"

Code: [Select]
RewriteRule ^photo_(.*)___(.*)$ watermark.php?img=./data/media/$1/$2and
Code: [Select]
<img src="./photo_{media_src2}__{media_src3}" border="1" alt="{image_name}"{width_height} /><br />
Does this suggestion fix it?
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on August 27, 2009, 07:49:25 PM
Hi,
      Actually earlier I changed this '__' to '_'  .. and may be for this I was getting this error.. Now I have changed it to '__'. let me see, whether this fix is working for me or not .  :)

Thanks
Batu
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on August 30, 2009, 06:49:09 AM
Sebas Bonito ,
                       Everything is working fine after applying your changes.. but when one user uploads a new picture.. at the completion of the upload, its not displaying the correct image, instead of that its displaying the same image which is in random image box..

Thanks,
batu544
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: WWTNET on August 30, 2009, 11:19:50 AM
Hello,

I don-t know why, but I get a blank image (not page) after making the changes for this mode.  all my images are now blank . . .  what could be the reason ?
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Sebas Bonito on August 30, 2009, 11:53:13 AM
Sebas Bonito ,
                       Everything is working fine after applying your changes.. but when one user uploads a new picture.. at the completion of the upload, its not displaying the correct image, instead of that its displaying the same image which is in random image box..

Thanks,
batu544


This has nothing to with my tiny modification  :wink:
By the way: For me the same (monthy before my short-url suggestion)  :lol:
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on August 30, 2009, 01:42:17 PM


This has nothing to with my tiny modification  :wink:
By the way: For me the same (monthy before my short-url suggestion)  :lol:

Hi,
      No, This problem is due to your tiny modification :)  ..  We need to make the same changes in member.php file also. I am not a php guru .. :) so,  don't know the exact rewrite line when the image will be stored in tmp_media folder...

WWTNET ,

            What changes you made and can you share your url with us, so that we can check the exact error..

Thanks
batu544
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: WWTNET on August 30, 2009, 02:53:26 PM
Hi,

Batu544, I managed to do the test with a fresh new installation of 4images.   it was probably a problem with the tests/modifications I did before.   your script works ok now.   I have only one more request.  .  . 

for displaying the image I use an image resizer script (just for display, does not affect the original photo), I have tried to merge the 2 scripts (resize+watermark) but it's over my PHP knowledge .  .  .   maybe someone can do this?

this is the resize script:

Code: [Select]
<?php
// Smart Image Resizer 1.4.1
// Resizes images, intelligently sharpens, crops based on width:height ratios, color fills
// transparent GIFs and PNGs, and caches variations for optimal performance

// Created by: Joe Lencioni (http://shiftingpixel.com)
// Date: August 6, 2008
// Based on: http://veryraw.com/history/2005/03/image-resizing-with-php/

/////////////////////
// LICENSE
/////////////////////

// I love to hear when my work is being used, so if you decide to use this, feel encouraged
// to send me an email. Smart Image Resizer is released under a Creative Commons
// Attribution-Share Alike 3.0 United States license
// (http://creativecommons.org/licenses/by-sa/3.0/us/). All I ask is that you include a link
// back to Shifting Pixel (either this page or shiftingpixel.com), but don&#8217;t worry about
// including a big link on each page if you don&#8217;t want to&#8211;one will do just nicely. Feel
// free to contact me to discuss any specifics (joe@shiftingpixel.com).

/////////////////////
// REQUIREMENTS
/////////////////////

// PHP and GD

/////////////////////
// PARAMETERS
/////////////////////

// Parameters need to be passed in through the URL's query string:
// image absolute path of local image starting with "/" (e.g. /images/toast.jpg)
// width maximum width of final image in pixels (e.g. 700)
// height maximum height of final image in pixels (e.g. 700)
// color (optional) background hex color for filling transparent PNGs (e.g. 900 or 16a942)
// cropratio (optional) ratio of width to height to crop final image (e.g. 1:1 or 3:2)
// nocache (optional) does not read image from the cache
// quality (optional, 0-100, default: 90) quality of output image

/////////////////////
// EXAMPLES
/////////////////////

// Resizing a JPEG:
// <img src="/image.php/image-name.jpg?width=100&amp;height=100&amp;image=/path/to/image.jpg" alt="Don't forget your alt text" />

// Resizing and cropping a JPEG into a square:
// <img src="/image.php/image-name.jpg?width=100&amp;height=100&amp;cropratio=1:1&amp;image=/path/to/image.jpg" alt="Don't forget your alt text" />

// Matting a PNG with #990000:
// <img src="/image.php/image-name.png?color=900&amp;image=/path/to/image.png" alt="Don't forget your alt text" />

/////////////////////
// CODE STARTS HERE
/////////////////////

if (!isset($_GET['image']))
{
header('HTTP/1.1 400 Bad Request');
echo 'Error: no image was specified';
exit();
}

define('MEMORY_TO_ALLOCATE', '100M');
define('DEFAULT_QUALITY', 90);
define('CURRENT_DIR', dirname(__FILE__));
define('CACHE_DIR_NAME', '/imagecache/');
define('CACHE_DIR', CURRENT_DIR CACHE_DIR_NAME);
define('DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT']);

// Images must be local files, so for convenience we strip the domain if it's there
$image preg_replace('/^(s?f|ht)tps?:\/\/[^\/]+/i''', (string) $_GET['image']);

// For security, directories cannot contain ':', images cannot contain '..' or '<', and
// images must start with '/'
$image substr($image1);
if (
$image{0} != '/' || strpos(dirname($image), ':') || preg_match('/(\.\.|<|>)/'$image))
{
header('HTTP/1.1 400 Bad Request');
echo 'Error: malformed image path. Image paths must begin with \'/\'';
exit();
}

// If the image doesn't exist, or we haven't been told what it is, there's nothing
// that we can do
if (!$image)
{
header('HTTP/1.1 400 Bad Request');
echo 'Error: no image was specified';
exit();
}

// Strip the possible trailing slash off the document root
$docRoot preg_replace('/\/$/'''DOCUMENT_ROOT);

if (!
file_exists($docRoot $image))
{
header('HTTP/1.1 404 Not Found');
echo 'Error: image does not exist: ' $docRoot $image;
exit();
}

// Get the size and MIME type of the requested image
$size GetImageSize($docRoot $image);
$mime $size['mime'];

// Make sure that the requested file is actually an image
if (substr($mime06) != 'image/')
{
header('HTTP/1.1 400 Bad Request');
echo 'Error: requested file is not an accepted type: ' $docRoot $image;
exit();
}

$width $size[0];
$height $size[1];

$maxWidth = (isset($_GET['width'])) ? (int) $_GET['width'] : 0;
$maxHeight = (isset($_GET['height'])) ? (int) $_GET['height'] : 0;

if (isset(
$_GET['color']))
$color preg_replace('/[^0-9a-fA-F]/''', (string) $_GET['color']);
else
$color FALSE;

// If either a max width or max height are not specified, we default to something
// large so the unspecified dimension isn't a constraint on our resized image.
// If neither are specified but the color is, we aren't going to be resizing at
// all, just coloring.
if (!$maxWidth && $maxHeight)
{
$maxWidth 99999999999999;
}
elseif (
$maxWidth && !$maxHeight)
{
$maxHeight 99999999999999;
}
elseif (
$color && !$maxWidth && !$maxHeight)
{
$maxWidth $width;
$maxHeight $height;
}

// If we don't have a max width or max height, OR the image is smaller than both
// we do not want to resize it, so we simply output the original image and exit
if ((!$maxWidth && !$maxHeight) || (!$color && $maxWidth >= $width && $maxHeight >= $height))
{
$data file_get_contents($docRoot '/' $image);

$lastModifiedString gmdate('D, d M Y H:i:s'filemtime($docRoot '/' $image)) . ' GMT';
$etag md5($data);

doConditionalGet($etag$lastModifiedString);

header("Content-type: $mime");
header('Content-Length: ' strlen($data));
echo $data;
exit();
}

// Ratio cropping
$offsetX 0;
$offsetY 0;

if (isset(
$_GET['cropratio']))
{
$cropRatio explode(':', (string) $_GET['cropratio']);
if (count($cropRatio) == 2)
{
$ratioComputed $width $height;
$cropRatioComputed = (float) $cropRatio[0] / (float) $cropRatio[1];

if ($ratioComputed $cropRatioComputed)
// Image is too tall so we will crop the top and bottom
$origHeight $height;
$height $width $cropRatioComputed;
$offsetY = ($origHeight $height) / 2;
}
else if ($ratioComputed $cropRatioComputed)
// Image is too wide so we will crop off the left and right sides
$origWidth $width;
$width $height $cropRatioComputed;
$offsetX = ($origWidth $width) / 2;
}
}
}

// Setting up the ratios needed for resizing. We will compare these below to determine how to
// resize the image (based on height or based on width)
$xRatio $maxWidth $width;
$yRatio $maxHeight $height;

if (
$xRatio $height $maxHeight)
// Resize the image based on width
$tnHeight ceil($xRatio $height);
$tnWidth $maxWidth;
}
else 
// Resize the image based on height
{
$tnWidth ceil($yRatio $width);
 
$tnHeight $maxHeight;
}

// Determine the quality of the output image
$quality = (isset($_GET['quality'])) ? (int) $_GET['quality'] : DEFAULT_QUALITY;

// Before we actually do any crazy resizing of the image, we want to make sure that we
// haven't already done this one at these dimensions. To the cache!
// Note, cache must be world-readable

// We store our cached image filenames as a hash of the dimensions and the original filename
$resizedImageSource $tnWidth 'x' $tnHeight 'x' $quality;
if (
$color)
$resizedImageSource .= 'x' $color;
if (isset(
$_GET['cropratio']))
$resizedImageSource .= 'x' . (string) $_GET['cropratio'];
$resizedImageSource .= '-' $image;

$resizedImage md5($resizedImageSource);

$resized CACHE_DIR $resizedImage;

// Check the modified times of the cached file and the original file.
// If the original file is older than the cached file, then we simply serve up the cached file
if (!isset($_GET['nocache']) && file_exists($resized))
{
$imageModified filemtime($docRoot $image);
$thumbModified filemtime($resized);

if($imageModified $thumbModified) {
$data file_get_contents($resized);

$lastModifiedString gmdate('D, d M Y H:i:s'$thumbModified) . ' GMT';
$etag md5($data);

doConditionalGet($etag$lastModifiedString);

header("Content-type: $mime");
header('Content-Length: ' strlen($data));
echo $data;
exit();
}
}

// We don't want to run out of memory
ini_set('memory_limit'MEMORY_TO_ALLOCATE);

// Set up a blank canvas for our resized image (destination)
$dst imagecreatetruecolor($tnWidth$tnHeight);

// Set up the appropriate image handling functions based on the original image's mime type
switch ($size['mime'])
{
case 'image/gif':
// We will be converting GIFs to PNGs to avoid transparency issues when resizing GIFs
// This is maybe not the ideal solution, but IE6 can suck it
$creationFunction 'ImageCreateFromGif';
$outputFunction 'ImagePng';
$mime 'image/png'// We need to convert GIFs to PNGs
$doSharpen FALSE;
$quality round(10 - ($quality 10)); // We are converting the GIF to a PNG and PNG needs a compression level of 0 (no compression) through 9
break;

case 'image/x-png':
case 'image/png':
$creationFunction 'ImageCreateFromPng';
$outputFunction 'ImagePng';
$doSharpen FALSE;
$quality round(10 - ($quality 10)); // PNG needs a compression level of 0 (no compression) through 9
break;

default:
$creationFunction 'ImageCreateFromJpeg';
$outputFunction   'ImageJpeg';
$doSharpen TRUE;
break;
}

// Read in the original image
$src $creationFunction($docRoot $image);

if (
in_array($size['mime'], array('image/gif''image/png')))
{
if (!$color)
{
// If this is a GIF or a PNG, we need to set up transparency
imagealphablending($dstfalse);
imagesavealpha($dsttrue);
}
else
{
// Fill the background with the specified color for matting purposes
if ($color[0] == '#')
$color substr($color1);

$background FALSE;

if (strlen($color) == 6)
$background imagecolorallocate($dsthexdec($color[0].$color[1]), hexdec($color[2].$color[3]), hexdec($color[4].$color[5]));
else if (strlen($color) == 3)
$background imagecolorallocate($dsthexdec($color[0].$color[0]), hexdec($color[1].$color[1]), hexdec($color[2].$color[2]));
if ($background)
imagefill($dst00$background);
}
}

// Resample the original image into the resized canvas we set up earlier
ImageCopyResampled($dst$src00$offsetX$offsetY$tnWidth$tnHeight$width$height);

if (
$doSharpen)
{
// Sharpen the image based on two things:
// (1) the difference between the original size and the final size
// (2) the final size
$sharpness findSharp($width$tnWidth);

$sharpenMatrix = array(
array(-1, -2, -1),
array(-2$sharpness 12, -2),
array(-1, -2, -1)
);
$divisor $sharpness;
$offset 0;
imageconvolution($dst$sharpenMatrix$divisor$offset);
}

// Make sure the cache exists. If it doesn't, then create it
if (!file_exists(CACHE_DIR))
mkdir(CACHE_DIR0755);

// Make sure we can read and write the cache directory
if (!is_readable(CACHE_DIR))
{
header('HTTP/1.1 500 Internal Server Error');
echo 'Error: the cache directory is not readable';
exit();
}
else if (!
is_writable(CACHE_DIR))
{
header('HTTP/1.1 500 Internal Server Error');
echo 'Error: the cache directory is not writable';
exit();
}

// Write the resized image to the cache
$outputFunction($dst$resized$quality);

// Put the data of the resized image into a variable
ob_start();
$outputFunction($dstnull$quality);
$data ob_get_contents();
ob_end_clean();

// Clean up the memory
ImageDestroy($src);
ImageDestroy($dst);

// See if the browser already has the image
$lastModifiedString gmdate('D, d M Y H:i:s'filemtime($resized)) . ' GMT';
$etag md5($data);

doConditionalGet($etag$lastModifiedString);

// Send the image to the browser with some delicious headers
header("Content-type: $mime");
header('Content-Length: ' strlen($data));
echo 
$data;

function 
findSharp($orig$final// function from Ryan Rud (http://adryrun.com)
{
$final $final * (750.0 $orig);
$a 52;
$b = -0.27810650887573124;
$c .00047337278106508946;

$result $a $b $final $c $final $final;

return max(round($result), 0);
// findSharp()

function doConditionalGet($etag$lastModified)
{
header("Last-Modified: $lastModified");
header("ETag: \"{$etag}\"");

$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ?
stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : 
false;

$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ?
stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) :
false;

if (!$if_modified_since && !$if_none_match)
return;

if ($if_none_match && $if_none_match != $etag && $if_none_match != '"' $etag '"')
return; // etag is there but doesn't match

if ($if_modified_since && $if_modified_since != $lastModified)
return; // if-modified-since is there but doesn't match

// Nothing has changed since their last request - serve a 304 and exit
header('HTTP/1.1 304 Not Modified');
exit();
// doConditionalGet()

// old pond
// a frog jumps
// the sound of water

// &#8212;Matsuo Basho
?>

As you can see, for output of the image I need to call this script.  .  .   <img src="image.  php?width=750&height=600&image={media_src}" alt="{image_name}" /> so I don-t think there is a possibility to call also watermark.  php as 2nd different script. 

Thanks,
A. 
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Sebas Bonito on August 30, 2009, 04:37:45 PM
This problem is due to your tiny modification

Sorry, sir... you mean the "on-fly" mod, but MY tiny modification above changes
nothing. It's just a rewrite stuff, nothing more  8)
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Fragezeichen on November 29, 2009, 12:52:19 PM
Many thanks for this Mod,it is more easy and useful than other Watermarkmod.
Just easy and quick to use and works without error... :D

Is it possible to have transparent background on WatermarkImage?
I was saved with transparente but it shows black bg
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on November 30, 2009, 12:09:38 PM
Rotlicht6 ,
                It should be transparent, if you are using a transparent  png file. I think you are doing some mistake in creating a transparent image. ( I have not much idea also in creating these images :) ) ..


Try once again with another transparent png file..


Thanks,
batu544
Title: Re: On-fly image annotation ( watermark).
Post by: Loda on December 08, 2009, 10:52:43 AM
Hi batu544 ...

2. if you want to show the watermark only to guests (non registered users), use this in your jpg.html ...
Code: [Select]
{if user_loggedin}<img src="{media_src}" border="1" alt="{image_name}"{width_height} /><br />{endif user_loggedin}
{if user_loggedout}<img src="./watermark.php?img={media_src}" border="1" alt="{image_name}"{width_height} /><br />{endif user_loggedout}

hallo,
wenn ich nun aber das bild bearbeiten anklicke, öffnet sich es zweimal im acp. hast du dafür noch eine lösung?
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on December 08, 2009, 02:24:45 PM
Hi Loda,
            I am sorry .. I didn't get your question correctly.. There is nothing related to ACP in this MOD. Please post your question in English.. so that it will be easier for me to understand it.

Thanks,
batu544
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Loda on December 08, 2009, 03:13:36 PM
ok,
if you click in the detail page on the edit link for an image you see two pictures in the edit page. mawenzi's code in the jpg.html is the reason i think.
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Yan on December 20, 2009, 12:16:54 AM
Why watermark not transparent? I use transparent png  :(
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Kobor on March 15, 2010, 10:49:30 PM
Hallo,

erstmal "Danke" für diesen Mod. Genau sowas habe ich gesucht :)
Leider habe ich aber ein Problem. Und zwar nimmt die Qualität der Bilder extrem ab sobald der Schriftzug (watermark.png) angezeigt wird.
Wenn ich mich jetzt einlogge ist die Qualität wieder im Original. Gibt es da eine Lösung?

Internetseite: xxx: foto-doden. de

Wäre sehr nett wenn ihr einen Tipp für mich hättet.

Gruß,
Jens
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Sunny C. on May 26, 2010, 04:55:20 PM
How Can I Add More Extension in this code.
e.g. png,gif ect.
---------------------------------------
Code: [Select]
<?php
header
('content-type: image/[b]jpeg[/b]');
$img $_GET['img'];
$watermark imagecreatefrompng('logo.png');
$watermark_width imagesx($watermark);
$watermark_height imagesy($watermark);
$image imagecreatetruecolor($watermark_width$watermark_height);
$image imagecreatefrom[b]jpeg[/b]("$img");
$size getimagesize("$img");
$dest_x $size[0] - $watermark_width 5;
$dest_y $size[1] - $watermark_height 730;
imagecopymerge($image$watermark$dest_x$dest_y00$watermark_width$watermark_height100);
image[b]jpeg[/b]($image);
imagedestroy($image);
imagedestroy($watermark);
?>

Das würde ich auch gerne wissen!
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on May 27, 2010, 03:27:23 PM
Sumale.nin,

                I am not sure .. but I think the below code should work fine for png, gif and jpg extensions..

Code: [Select]
<?php

$img 
$_GET['img'];
$watermark imagecreatefrompng('watermark.png');

$watermark_width imagesx($watermark);
$watermark_height imagesy($watermark);
$image imagecreatetruecolor($watermark_width$watermark_height);
//$image = imagecreatefromjpeg("$img");
$image = @imageCreateFromString(file_get_contents("$img"));
$size getimagesize("$img");
$dest_x $size[0] - $watermark_width 5;
$dest_y $size[1] - $watermark_height 5;

header("Content-Type: ".$size['mime']);

imagecopy($image$watermark$dest_x$dest_y00$watermark_width$watermark_height);

//imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
//imagejpeg($image);
   
switch ($size[2]) {
      case 
1:
         
imageGIF($image);
         break;
      case 
2:
         
imageJPEG($imageNULL100);
         break;
      case 
3:
         
imagePNG($image);
         break;
         }

imagedestroy($image);
imagedestroy($watermark);
return 
true ;
?>


MrAndrew (http://www.4homepages.de/forum/index.php?action=profile;u=28405) ,

   Never mind, one or two points are influenced by your code..  :)



Thanks,
batu544
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: scrat on May 31, 2010, 07:25:25 PM
habe das mal eingebaut, bekomme aber nur in den details statt des bildes nur ein großes weisses viereck ausgegeben...das bild bekomme ich nicht angezeigt..hat einer ne lösung?
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on May 31, 2010, 09:15:34 PM
scrat,
          Please let us know, what exactly you did ?

Thanks,
batu544
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: scrat on May 31, 2010, 10:40:25 PM
ok...thats not problem.In the details from pic, i become follow graphic:
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: batu544 on June 01, 2010, 01:24:30 PM
hi,
    Please provide your website link.. let me see the error in actuals.. may be I can help you after that..

Thanks,
batu544
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: scrat on June 02, 2010, 04:07:57 PM
hehe ich depp hatte vergessen, das watermark.png in den root zu laden...läuft alles fehlerfrei....sorry :mrgreen: :mrgreen: :mrgreen:
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: __G__ on June 21, 2010, 06:49:08 AM
HI it works  fine with jpeg but when im trying to make this work with png its not working help please how can i make this work with .png also

Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: henary on December 11, 2010, 11:21:59 PM
Hello,
ok,
if you click in the detail page on the edit link for an image you see two pictures in the edit page. mawenzi's code in the jpg.html is the reason i think.
is there any solution for this?

I 'll explain again: While using
Code: [Select]
{if user_loggedin}<img src="{media_src}" border="1" alt="{image_name}"{width_height} /><br />{endif user_loggedin}
{if user_loggedout}<img src="./watermark.php?img={media_src}" border="1" alt="{image_name}"{width_height} /><br />{endif user_loggedout}
in jpg.html you will see in ACP during editing image the image twice.

May it's possible to use a different template for jpg in ACP/edit Image by user?

Thanks for any hint,
Henry
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: sigma. on January 09, 2011, 05:25:42 PM
Anyone know why my watermark would show up like this?

see attached

Its a png with black text. I've tried it with white text also. just shows up as a box. tested in chrome and firefox.

Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: sigma. on January 12, 2011, 06:33:54 AM
Looks like it doesnt like PNG-24, only PNG-8 works on my site.
Either way its working.

Is there a way to use it only on certain categories?
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: milanNN on January 25, 2011, 03:48:20 PM
Is it possible to add photodrapher name on watermark?
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Jasi on February 22, 2011, 12:52:55 PM
+++ DONE +++

Hat sich erledigt ;-)


Kann mir mal bitte jemand helfen wie ich korrekt ohne PARSER-ERROR den

./watermark.php?={media_src}

in den IMG Tag (Code) schreiben muss da ich diesen MOD ( http://www.4homepages.de/forum/index.php?topic=18326.0 )

http://www.4homepages.de/forum/index.php?topic=18326.0 (http://www.4homepages.de/forum/index.php?topic=18326.0)

für die media/jpg.html nutze und dort wird die Bilddatei ja als src="'.$media_src.'" geführt. Komme irgendwie nicht zurecht, denn mir wird nur ein ROTES KREUZ und kein Bild angezeigt.

Danke Euch
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: Jan-Lukas on June 25, 2012, 11:35:28 PM
Teste jetzt schon eine Weile, will aber nicht klappen

Habe den Code ja so angepasst, was auch bestens klappt
<!-- Template file for JPG Files -->
<table border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td background="{media_src}">
      {if user_loggedin}<img src="{template_url}/images/spacer.gif" border =" 0" alt="{image_name}" {width_height}usemap="#navi" border="0" vspace="0" hspace="0" align="absmiddle" /><br />{endif user_loggedin}
{if user_loggedout}img src="./watermark.php?img={media_src}" border="1" alt="{image_name}"{width_height} /><br />{endif user_loggedout}
 
    </td>
  </tr>
</table>

Nur möchte ich zu dem Wasserzeichen auch noch das spacer.gif mit reinnehmen, damit man z.B. im FF mit "Grafik anzeigen" das spacer.gif zu sehen bekommt, wie als eingeloggter User.

LG

Edit:

gelöst  :wink:

<!-- Template file for JPG Files -->
<table border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td background="{media_src}">
      {if user_loggedin}<img src="{template_url}/images/spacer.gif" border =" 0" alt="{image_name}" {width_height}usemap="#navi" border="0" vspace="0" hspace="0" align="absmiddle" /><br />{endif user_loggedin}
    </td>
<td background="./watermark.php?img={media_src}">
{if user_loggedout}<img src="{template_url}/images/spacer.gif" border =" 0" alt="{image_name}" {width_height}usemap="#navi" border="0" vspace="0" hspace="0" align="absmiddle" /><br />{endif user_loggedout}
</td>
  </tr>
</table>
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: paule on August 30, 2012, 03:37:11 PM
Hallo,

habe wz-tooltip installiert.
Der Mod funktioniert bei mir leider nicht.
Kann das mit dem WZ-Tooltip zusammenhängen???

Beste Grüße

paule
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: kumotobi on September 14, 2012, 01:53:47 AM
Can be used on Gif picture?
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: alghorabaa on June 15, 2013, 08:24:10 AM
I tried it, and it works fine!

but when the registered user tries to download the image, he can download it without watermark, and the same also he can download the zipped image without watermark, how can we modify the page (download.php) to force it download the watermarked image?

thanks
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: mawenzi on June 16, 2013, 02:40:19 PM
@ alghorabaa

try this : http://www.4homepages.de/forum/index.php?topic=13719.0
Title: Re: [MOD] On-fly image annotation ( watermark)
Post by: alghorabaa on June 16, 2013, 03:37:30 PM
Hi, Thank you for the link!

I just installed the MOD, everything looked fine, I changed all values inside the admin area, but no watermark appears...

It seems that this problem is already noticed because the last posts were about the same issue, so that I expect no problems in my side... any idea?

http://www.4homepages.de/forum/index.php?topic=13719.915

thanks again