watermarking
semisphere
Joined: 2003-02-19
Posts: 8 |
![]() |
Hi everyone, I wanted to apply dynamic watermarks on all my images, so I came up with this simple hack. enjoy =) <? require($GALLERY_BASEDIR . "init.php"); global $gallery; // A quick little hack to place a watermark on all images // configuration settings $scale = 25; // get the file we want to watermark // get the image details and create an image // get the watermark details, and open it // calculate scale of watermark and create scaled watermark // resize the watermark to the new scale // set the transparent color (black) // add the watermark to the image // send out a header // send the image // clean up ?> |
|
Jmallow
![]()
Joined: 2003-02-19
Posts: 10 |
![]() |
Does this work with all pictures currently uploaded or just ones you upload? |
|
semisphere
Joined: 2003-02-19
Posts: 8 |
![]() |
Quote:
Does this work with all pictures currently uploaded or just ones you upload? its dynamic. it works with any images which are loaded. |
|
skicrave
Joined: 2002-10-25
Posts: 89 |
![]() |
Great mod, I especially like the flexibility it has. I'm having some problems though. All I get is broken images. If I look at the URL for the images, they are all missing the album they are associated with. The path goes straight from the albums directory to the image name, without specifying the unique album the image came from. Can you think of anything specific I should check? |
|
Jmallow
![]()
Joined: 2003-02-19
Posts: 10 |
![]() |
Try: <!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE><?php</TD></TR></TABLE><!-- BBCode End --> instead of just I'm still getting errors. If you have Red Hat 8.0 you gotta compile GD 2.0 on the server, and upgrade a few things. I'm still working on it. |
|
skicrave
Joined: 2002-10-25
Posts: 89 |
![]() |
Thanks Jmallow. I'll let you know if I get things working. |
|
vallimar
Joined: 2002-08-15
Posts: 487 |
![]() |
Actually, if you want to use GD, then you are better off using php 4.3.x |
|
Jmallow
![]()
Joined: 2003-02-19
Posts: 10 |
![]() |
I'm going to upgrade to the newest version of PHP tomorrow. I'll let you all know of my results after testing it. |
|
semisphere
Joined: 2003-02-19
Posts: 8 |
![]() |
Quote:
Great mod, I especially like the flexibility it has. I'm having some problems though. what version of gallery are you using? |
|
Jmallow
![]()
Joined: 2003-02-19
Posts: 10 |
![]() |
skicrave
Joined: 2002-10-25
Posts: 89 |
![]() |
I'm running 1.3.3, and the install can be seen <!-- BBCode Start --><A HREF="http://www.malibuboatowners.com/galltest" TARGET="_blank">here</A><!-- BBCode End -->. The URL does contain the image name, but not it's associated album directory name. So instead of something like this: you get this: |
|
Jmallow
![]()
Joined: 2003-02-19
Posts: 10 |
![]() |
http://www.mallowweb.com/gallery/watermark.php?image_file=/carshow/aaa.sized.jpg Your test gallery doesn't work |
|
Otto
Joined: 2003-02-16
Posts: 14 |
![]() |
The reason it's not working is those warnings being output. You need to disable them. |
|
phgrove
Joined: 2002-10-10
Posts: 101 |
![]() |
Will this mod only work with jpeg images or will it work with all types of inages? Peter |
|
alindeman
![]()
Joined: 2002-10-06
Posts: 8194 |
![]() |
Or you need to install GD 2.0, which is what the warnings are complaining about... |
|
phgrove
Joined: 2002-10-10
Posts: 101 |
![]() |
I have adjusted the script slightly but i can't get it to work. The script is as follows:- <?php require($GALLERY_BASEDIR . "init.php"); global $gallery; // A quick little hack to place a watermark on all images // What are the websites (hostnames) that can use this $referrer = getenv( "HTTP_REFERER" ); //Get the refferer URL function isreferrerokay ( $referrer, $validprefixes ) // What is your email address? // What is the main page of your website? Visitors will // configuration settings $scale = 25; if (isset($image_file)) { // get the file we want to watermark // get the image details and create an image //Load in the image correctly // get the watermark details, and open it // calculate scale of watermark and create scaled watermark // resize the watermark to the new scale // set the transparent color (black) is this needed? // add the watermark to the image // send out a header and anticache headers // send the image // clean up ?> Any ideas? Peter |
|
joan
![]()
Joined: 2002-10-21
Posts: 3473 |
![]() |
phgrove Have you actually read the error messages? Quote:
Warning: getimagesize(/home/public_html/gallery/images/watermark.png) [function.getimagesize]: failed to create stream: No such file or directory in /home/www/petergro/gallery/watermark.php on line 111 So, does the file /home/public_html/gallery/images/watermark.png exist? If not, then fix that. Then see what fixing that does. |
|
phgrove
Joined: 2002-10-10
Posts: 101 |
![]() |
Sorry i changed the script before posting it into the forum, so that all my paths weren't given away, and uploaded it which i shouldn't have done! I have fixed it now so you will see the proper messages. I have tried it, if it doesn't work the first time hit reload and you will get the messages. Thanks Peter |
|
joan
![]()
Joined: 2002-10-21
Posts: 3473 |
![]() |
http://www.petergrove.co.uk/gallery/watermark.php?image_file=/album71/07_10.jpg??? There are no error messages there now. However, it's a html file, not a jpeg. This is where I drop out, as I haven't installed this script. But if that's supposed to be a jpg, there's something really wrong as the contents are |
|
phgrove
Joined: 2002-10-10
Posts: 101 |
![]() |
I get these warning int he browser:- Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/www/petergro/gallery/watermark.php on line 130 Warning: imagecopymerge(): supplied argument is not a valid Image resource in /home/www/petergro/gallery/watermark.php on line 137 Warning: Cannot modify header information - headers already sent by (output started at /home/www/petergro/gallery/watermark.php:130) in /home/www/petergro/gallery/watermark.php on line 140 Warning: Cannot modify header information - headers already sent by (output started at /home/www/petergro/gallery/watermark.php:130) in /home/www/petergro/gallery/watermark.php on line 141 Warning: Cannot modify header information - headers already sent by (output started at /home/www/petergro/gallery/watermark.php:130) in /home/www/petergro/gallery/watermark.php on line 142 Warning: Cannot modify header information - headers already sent by (output started at /home/www/petergro/gallery/watermark.php:130) in /home/www/petergro/gallery/watermark.php on line 143 Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/www/petergro/gallery/watermark.php on line 146 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/www/petergro/gallery/watermark.php on line 149 Any further ideas Peter |
|
joan
![]()
Joined: 2002-10-21
Posts: 3473 |
![]() |
Time to learn how to debug. Generally the best approach is to only look at the first error: it's possible all the rest are side effects of that. For instance: Quote:
Warning: Cannot modify header information - headers already sent by (output started at /home/www/petergro/gallery/watermark.php:130) in /home/www/petergro/gallery/watermark.php on line 140 is caused by printing the first error, before sending the html header information. It will disappear when you get rid of the errors. Quote:
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/www/petergro/gallery/watermark.php on line 130 is your first error, presumably generated by this You need to add a diagnostic. Try adding this, right above line 130: |
|
phgrove
Joined: 2002-10-10
Posts: 101 |
![]() |
thanks that will help me Peter |
|
joan
![]()
Joined: 2002-10-21
Posts: 3473 |
![]() |
Quote:
+ all the other messages. Is it a case that the 2 images must be of the same type, eg both jpegs? No, they look fine. I'm out - you'll have to wait until someone who has this script running comes online. |
|
phgrove
Joined: 2002-10-10
Posts: 101 |
![]() |
I got it all sorted, it was what i thourgh wa the problem inthe first place. The wrong varaible name used at the wrong place, too many $image_ arounbd. Thanks for the debug code to dump the varaible out, without that i would have struggled. Peter :smile: |
|
jflaflamme
Joined: 2003-02-26
Posts: 34 |
![]() |
Today, i was wondering why the watermarking was still buggy... so i finally recode a part of it ... INCLUDING SUPPORT FOR TEXT WATERMARK'S :smile: Zip, screenshots and tarball availables at :<!-- BBCode Start --><A HREF="http://www.votremedia.com/gallery/watermark_mod" TARGET="_blank">http://www.votremedia.com/gallery/watermark_mod</A><!-- BBCode End --> Package include : watermark.php and modified classes/Album.php P.S Please ignore my poor english, je suis Quebecois stie ! comments are welcome jflaflamme@votremedia.com |
|
phgrove
Joined: 2002-10-10
Posts: 101 |
![]() |
I have been trying to fix a problem with my watermarking script. Currently it works, but what i would like to do is check that the referrer is from my domain only. For some reason when i get the script to print out what the referrer's doamin is it is empty, as though i couldn't get the enviroment variable HTTP_REFERRER. This is the function that check the referrer's domain name. function isreferrerokay ( $referrer, $validprefixes ) This is the beginning of my watermarking script. $referrer = getenv( "HTTP_REFERER" ); //Get the refferer URL if (empty($referrer) || isreferrerokay( $referrer, $validprefixes )) { // function getAlbumDirURL($type) Any idea's on whay the variable would be empty? Peter |
|
skicrave
Joined: 2002-10-25
Posts: 89 |
![]() |
Thanks for contributing your script jflaflamme! Just be aware, it is very resource intensive. I guess it's related to the fact that it builds the watermarked image for each view, but I had to take it down because of the additional bandwidth used. |
|
MaxHeadroom
Joined: 2003-03-05
Posts: 1 |
![]() |
Quote:
Today, i was wondering why the watermarking was still buggy... |
|
jflaflamme
Joined: 2003-02-26
Posts: 34 |
![]() |
Hi, thanks for the information about the missing file, ZIP file has been fixed now... Well, this is possible to modify the images right after the upload process, is it true that it will help processing time, but for me, i prefer to keep the images intact for now, but maybe in the future i will change it to write them after the upload. This is not complicated. I don't want to modify to much this script, because un Gallery2, that's gonna be different so ... About your error : Did you configure the watermark.php correctly ? line 104, this is where the variable about your image is, this isn't supposed to append Feel free to email me at jflaflamme@votremedia.comor ICQ 7561558 When i'll have some free time, i will modify the watermark.php to look for the pixel colors where the watermak goes, to have nearly the right background color, this will prevent text/image to appear chunky on the corners/borders, but this isn't 100% perfect, except if all the images have the same background color, which is not common. Jean-Francois Laflamme jflaflamme@votremedia.com |
|
semisphere
Joined: 2003-02-19
Posts: 8 |
![]() |
Well, its been a few weeks since I posted my initial hack, and its suprising to see how many peopl have been discussing it! =) I have since worked on making the images cacheable, and also fixing a bug that prevented IE5.5 or IE6 from correctly caching the image. I have now added the following code: 1. Generate unique filename for the image (for those how want "save images as") 2. Cache images for 3 days 3. Fix ie5.5, ie6 caching bug // get the file we want to watermark By not using galleries init.php we save a bit of preocessing, but also we don't send out a whole bunch of cookies that seem to throw ie5.5+ and prevent them from caching the image. Anyway, I hope people find these modifications useful. Also, for those of you with access to mod_rewrite (I dont'), you could scrab modifing Albums.php and just use a rewrite in the albums dir to pass the request through the watermark. Thats another challenge I leve up to the reader =) |
|
jdr0606
Joined: 2003-01-06
Posts: 63 |
![]() |
The script works great for images, but when I try and open a flash (.swf) file, I'm getting some error messages. Warning: imagecreatefromjpeg: 'c:/phpdev/imagestore/gallery/albums/dina_meyer/card2_1.swf' is not a valid JPEG file in c:phpdevwwwpersonalnukehtmlmodulesgallerywatermark.php on line 55 Warning: imagecopymerge(): supplied argument is not a valid Image resource in c:phpdevwwwpersonalnukehtmlmodulesgallerywatermark.php on line 75 Warning: Cannot add header information - headers already sent by (output started at c:phpdevwwwpersonalnukehtmlmodulesgallerywatermark.php:55) in c:phpdevwwwpersonalnukehtmlmodulesgallerywatermark.php on line 78 Warning: imagejpeg(): supplied argument is not a valid Image resource in c:phpdevwwwpersonalnukehtmlmodulesgallerywatermark.php on line 81 Warning: imagedestroy(): supplied argument is not a valid Image resource in c:phpdevwwwpersonalnukehtmlmodulesgallerywatermark.php on line 84 What can I do to eliminate the errors? Thanks |
|
semisphere
Joined: 2003-02-19
Posts: 8 |
![]() |
you'll need to descriminate against jpeg and non-jpeg content. I only use jpeg images, so I can assume that I want to watermark everything. In the watermark.php code, you should check the extension of the file, and if its .swf (or something else), you should just read the file, send an appropriate Content-Type header and then send the file data. Alternatively, you could check for this in the modified code in Albums.php, and return the non-watermarked AlbumURL if the file type is not jpeg. |
|
semisphere
Joined: 2003-02-19
Posts: 8 |
![]() |
For those of you who want to see my watermarking script in action, have a look here: http://www.freshdisko.com/photos/ I'm only using GD 1.0, so no fancy blending which would be possible with GD 2.0. Please note - DO NOT email the site maintainers of freshdisko.com asking for help with these scripts. If you do, you will be ignored (sorry, no time to reply!) I have posted this link purely as an example. cheers. |
|
zake
Joined: 2002-10-20
Posts: 6 |
![]() |
Perhaps I'm missing something, but does this modify the images on the server or add the watermark dynamically when the image is sent to the browser? |
|
semisphere
Joined: 2003-02-19
Posts: 8 |
![]() |
it does it dynamically. I can change the watermark whenever I want. |
|
diomark
![]()
Joined: 2003-03-14
Posts: 90 |
![]() |
This wouldn't work if images are getting served from a different server though; would it? (I'm using a secondary server hosted with an ISP to serve images on http://mvgals.net ; with the primary server being served from my dsl connection...) Has anyone came with a simple hack to watermark the pictures as they're being uploaded? |
|
nunor
Joined: 2003-03-25
Posts: 2 |
![]() |
Does anyone was able to get the watermark mod to work? |
|
jdr0606
Joined: 2003-01-06
Posts: 63 |
![]() |
I'm trying to check the extension of images/files in Album.php to decide whether to Watermark or not but I can't figure out how to do the check. Any Ideas? Thanks |
|
joan
![]()
Joined: 2002-10-21
Posts: 3473 |
![]() |
in the AlbumItem class, the image extension is called type, and there's a function called "isImage" Depends on how you are writing the code, but I expect something like this is what is required: if ($photo->isImage() { |
|
jdr0606
Joined: 2003-01-06
Posts: 63 |
![]() |
Thanks! I want to go one step further to check whether it is a .gif vs .jpg type. Jeff... |
|
jdr0606
Joined: 2003-01-06
Posts: 63 |
![]() |
Joan, any suggestions how to check what the file type is in Album.php. Everything I try gives me a non-object error. Thanks |
|
joan
![]()
Joined: 2002-10-21
Posts: 3473 |
![]() |
It only makes sense to do this to an image. What image do you want to watermark from Albums.php? I can only imagine watermarking in view_photo.php |
|
jdr0606
Joined: 2003-01-06
Posts: 63 |
![]() |
Joan, well what I've got is an album that has jpeg, gif, mpeg and mov files. The watermarking as defined only works for jpeg files so I want to do a file type check to determine whether to pass to the watermak.php program. Hope that makes sense. Jeff... |
|
phgrove
Joined: 2002-10-10
Posts: 101 |
![]() |
This is code you probably are wanting. Hope it helps <!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE> <?php require($GALLERY_BASEDIR . "init.php"); global $gallery; // A quick little hack to place a watermark on all images // What are the websites (hostnames) that can use this function isreferrerokay ( $referrer, $validprefixes ) // What is your email address? // What is the main page of your website? Visitors will // configuration settings $scale = 4; if (isset($image_file)) { $referrer = getenv( "HTTP_REFERER" ); //Get the refferer URL //empty($referrer) is needed as they might have typed the URL directly! //Get extension and check that it is of a type image. if ((($ext=="jpg")||($ext=="gif")|($ext=="jpeg")|($ext=="png"))) { // get the image details and create an image //Load in the image correctly // get the watermark details, and open it // calculate scale of watermark and create scaled watermark // resize the watermark to the new scale // set the transparent color (black) is this needed? // add the watermark to the image // send out a header and anticache headers // send the image // clean up $referrer } $referrer ?> </TD></TR></TABLE><!-- BBCode End --> |
|
jdr0606
Joined: 2003-01-06
Posts: 63 |
![]() |
I replaced my existing watermark.php with the code (Posted: Apr 01, 2003 - 07:14 PM), however when I run gallery all my images show as a red x. Is there something else I need to do. BTW, the watermark code I was using before worked fine as long as the image file was jpeg. Thanks Jeff... |
|
phgrove
Joined: 2002-10-10
Posts: 101 |
![]() |
The code above works fine for me. Have you got the path to your watermark image right, if you haven't that that could cause it. Basically for the images to have a red X means either it couldn't find the image to have the watermark added or it couldn't find the watermark image file. I have only tried this code with a PNG water image and nothing else. If you want the watermark image get it from http://www.petergrove.co.uk/gallery/images/watermark.png Peter |
|
jdr0606
Joined: 2003-01-06
Posts: 63 |
![]() |
Thanks for the followup! I checked the path to my jpeg watermark image and it was fine so I created the image as a png file but it still displays the red x on the images. Unfortunately I'm running this on a localhost so I can't provide access to my development site. Jeff... |
|
mlaia
Joined: 2002-11-01
Posts: 44 |
![]() |
Hi People, I download the jflaflamme's script (<!-- BBCode Start --><A HREF="http://www.votremedia.com/gallery/watermark_mod" TARGET="_blank">http://www.votremedia.com/gallery/watermark_mod</A><!-- BBCode End -->) and install it. But, now, the gallery dont show the pictures and in it show a red "X" !!!! What is the problem??? My OS is win with php4.3.0 with GD2. Thanks Marcelo |
|
nunor
Joined: 2003-03-25
Posts: 2 |
![]() |
I have exactly the same problem .. not images files are shown :sad: with the watermark file enabled, then all the images are called like http://myserver/watermark.php?image_file=/test/myimage.jpg Is the path correctly directed where the image files are stored? I tried with gallery installed on a linux & windows machine with GD 2.0 installed |
|
mlaia
Joined: 2002-11-01
Posts: 44 |
![]() |
Hi people, I executed the jflaflamme's script <!-- BBCode Start --><A HREF="http://my.domain.com/gallery/watermark.php?image_file=watermark.jpg" TARGET="_blank">http://my.domain.com/gallery/watermark.php?image_file=watermark.jpg</A><!-- BBCode End --> and I noted a few goods: errors. Quote:
Warning: getimagesize(f:/webdoc/gallery/albumswatermark.jpg) [function.getimagesize]: failed to create stream: No such file or directory in f:webdocgallerywatermark.php on line 110 My watermark is in the f:\webdoc\gallery\images\watermark.jpg Thanks Marcelo :cry: |
|
mlaia
Joined: 2002-11-01
Posts: 44 |
![]() |
HI everyone How do I do for download/install the IsoLatin1.enc and helvetica.pfb? I use Debian. I am sorry for this OFF TOPIC in this forum. Thanks Marcelo |
|