Pages (4):    1 2 3 4   
Member
Member
Skwid   17-06-2006, 00:28
#21

Hey everyone,

I did my 'watermarking' my own way ! Using text rather than images. This way, the text can be easily changed by editing the setting in zp-config.php, and there is no need to create an image.

You can see it here (just get to an image)
http://test.lostocean.net/zp/

The code calculates the text color based on the average color of the area that is underneath !

Developer
Developer
trisweb   18-06-2006, 16:40
#22

Looks pretty cool Skwid, think you could make it transparent and anti-aliased?

If you want, bundle it up and submit a patch at http://bugs.zenphoto.org.

Member
Member
thinkdreams   18-06-2006, 18:23
#23

In case anyone wanted to see it in action, I have a zenphoto implementation up at http://www.photosbydaisy.com/zenphoto which is utilizing Skwid's watermarking function.

Thinkdreams

Member
Member
Skwid   18-06-2006, 18:42
#24

Hum trisweb, I'm not sure if i can make transparent text using GD functions, plus it would be hard to read it ...

By the way, I wrote you an email, but never had an answer. If you didn't have time that's fine, but if you didn't get it, please tell me so I can resend it.

Member
Member
thinkdreams   18-06-2006, 20:36
#25

This might do the trick:

http://www.phpbuilder.com/snippet/download.php?type=snippet&id=68

I haven't had a chance to try it yet though. It solves the different font thing we were talking about the other night Skwid.

Member
Member
Skwid   19-06-2006, 01:20
#26

Ok, I got the watermarking working with a transparent PNG made from custom text, font, color, whatever

You can see it in action at the usual URL:

http://test.lostocean.net/zp

This is color transparency, i still need to work on alpha transparency.
I still need to polish it a little.. but it works !

Member
Member
nathan   20-06-2006, 09:52
#27

Oh... Crap. I forgot to upload the article. Gimmie a sec and I will do it now.

I use images, but the script handles alpha transparency, anti-aliasing and png-24 formatted images (the big plus for quality).

Member
Member
nathan   20-06-2006, 10:20
#28

Okay. First of all, sorry for being late. I completely forgot about it.

Here is what needs to be done. For ease of configuration, there are some changes to the zp-config.php file AS WELL as the i.php file. I will try and step it out with easy instructions, but if I am unclear on anything, please let me know. This will eventually be the wiki page.

  1. We will add the extra variables to the zp-config.php and get that out of the way.

`

// turn the watermarking on and off

$conf['perform_watermark'] = true;

// the image (png-24) in the zen/images/ directory

$conf['watermark_image'] = "images/watermark.png";

`

You can add those anywhere ABOVE the line that says:
`

/ Do not edit below this line. /

/**/

`

  1. Put the variables (the rest seem to be up there) at the top of the i.php file (for convenience).

`

$perform_watermark = zp_conf('perform_watermark');

$watermark_image = zp_conf('watermark_image');

`

  1. Add the watermarking code to the i.php file. It needs to go (as of 1.0.3) in at about line 213, just before the // Create the cached file (with lots of compatibility)...

`

    //-- watermarking

    if ($perform_watermark == true) {

        $watermark = imagecreatefrompng($watermark_image);

        imagealphablending($watermark, false);

        imagesavealpha($watermark, true);

        $watermark_width = imagesx($watermark);

        $watermark_height = imagesy($watermark);

        // Position Overlay in Bottom Right

        $dest_x = imagesx($newim) - $watermark_width;

        $dest_y = imagesy($newim) - $watermark_height;

        imagecopy($newim, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);

        imagedestroy($watermark);

    }

    //-- /watermarking

`

That is it. Make sure you put the image in the zen/images/ directory and it will work.

This WILL also add the watermark to the thumbs. To turn that off, add this line in the thumbnailing part og the i.php file (about line 62). Right after the $thumb = true;.

$perform_watermark = false;

Is that wiki worthy?

Member
Member
thinkdreams   20-06-2006, 16:59
#29

works good for me nathan. the image is a 50% opacity .png created with a text font in photoshop.

http://www.thinkdreams.com/devzp/scenery/IMG_3280.JPG

Member
Member
nathan   20-06-2006, 23:56
#30

Great.

I'll tidy up the text/ grammar and add it to the wiki.

Member
Member
DarrellD   21-06-2006, 04:18
#31

Very nice solution to watermarking.

The only problem that I have with this hack is that it will only work for those themes which use values set in zp-config.php because those themes use the [b]getImageThumb()[/b] and [b]printImageThumb()[/b] functions. For both of my themes, I never used those because I wanted to basically "hard-code" (i.e. [b]getCustomImageURL()[/b]) the sizes of the thumbnails. In order to get it to work with that function, I'll have to do some major work with [b]i.php[/b] and even [b]classes.php[/b].

Also, I'd like to make a suggestion to your code.
Instead of having you copy & paste code in three different areas of [b]i.php[/b], just copy and paste the following into i.php "at about line 213, just before the // Create the cached file (with lots of compatibility)"

`////////////////////////////////////////////////////////////////////////////////

// Watermark Hack

////////////////////////////////////////////////////////////////////////////////

$perform_watermark = zp_conf('perform_watermark');

$watermark_image = zp_conf('watermark_image');

if ($perform_watermark == true && $thumb == false) {

    $watermark = imagecreatefrompng($watermark_image);

    imagealphablending($watermark, false);

    imagesavealpha($watermark, true);

    $watermark_width = imagesx($watermark);

    $watermark_height = imagesy($watermark);

    // Position Overlay in Bottom Right

    $dest_x = imagesx($newim) - $watermark_width;

    $dest_y = imagesy($newim) - $watermark_height;

    imagecopy($newim, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);

    imagedestroy($watermark);

}

////////////////////////////////////////////////////////////////////////////////`

This code also takes care of the fact that it's a thumbnail.

Member
Member
DarrellD   21-06-2006, 05:23
#32

Okay, after further thought, here goes a fix that will work for my themes (and maybe others that use the [b]getCustomImageURL()[/b]). The only thing is that you'll have to edit more than just [b]i.php[/b].

copy and paste the following code into [b]i.php[/b] around line 213 (just as stated in the above post):

`////////////////////////////////////////////////////////////////////////////////

// Watermark Hack

////////////////////////////////////////////////////////////////////////////////

$perform_watermark = zp_conf('perform_watermark');

$watermark_image = zp_conf('watermark_image');

if ($perform_watermark == true && $thumb == false && $_GET['wm'] == true) {

    $watermark = imagecreatefrompng($watermark_image);

    imagealphablending($watermark, false);

    imagesavealpha($watermark, true);

    $watermark_width = imagesx($watermark);

    $watermark_height = imagesy($watermark);

    // Position Overlay in Bottom Right

    $dest_x = imagesx($newim) - $watermark_width;

    $dest_y = imagesy($newim) - $watermark_height;

    imagecopy($newim, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);

    imagedestroy($watermark);

}

////////////////////////////////////////////////////////////////////////////////`

now from lines 257-263 of [b]classes.php[/b] change the function from:

`function getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy) {

return WEBPATH . "/zen/i.php?a=" . urlencode($this->album->name) . "&i=" . urlencode($this->filename)

. ($size ? "&s=$size" : "" ) . ($width ? "&w=$width" : "") . ($height ? "&h=$height" : "") 

. ($cropw ? "&cw=$cropw" : "") . ($croph ? "&ch=$croph" : "")

. ($cropx ? "&cx=$cropx" : "") . ($cropy ? "&cy=$cropy" : "") ;

}`

to the following:

`function getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy, $wm=true) {

return WEBPATH . "/zen/i.php?a=" . urlencode($this->album->name) . "&i=" . urlencode($this->filename)

. ($size ? "&s=$size" : "" ) . ($width ? "&w=$width" : "") . ($height ? "&h=$height" : "") 

. ($cropw ? "&cw=$cropw" : "") . ($croph ? "&ch=$croph" : "")

. ($cropx ? "&cx=$cropx" : "") . ($cropy ? "&cy=$cropy" : "")

 . ($wm ? "&wm=$wm" : "") ;

}`

Then in [b]template-functions.php[/b] change lines 554-558 from:

`function getCustomAlbumThumb($size, $width=NULL, $height=NULL, $cropw=NULL, $croph=NULL, $cropx=NULL, $cropy=null) {

global $_zp_current_album;

$thumb = $_zp_current_album->getAlbumThumbImage();

return $thumb->getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy);

}`

to the following:

`function getCustomAlbumThumb($size, $width=NULL, $height=NULL, $cropw=NULL, $croph=NULL, $cropx=NULL, $cropy=null, $wm=false) {

global $_zp_current_album;

$thumb = $_zp_current_album->getAlbumThumbImage();

return $thumb->getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy, $wm);

}`

Also in [b]template-functions.php[/b] change lines 892-903 from:

`function getCustomImageURL($size, $width=NULL, $height=NULL, $cropw=NULL, $croph=NULL, $cropx=NULL, $cropy=NULL) {

global $_zp_current_image;

return $_zp_current_image->getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy);

}`

`function printCustomSizedImage($alt, $size, $width=NULL, $height=NULL, $cropw=NULL, $croph=NULL, $cropx=NULL, $cropy=NULL, $class=NULL, $id=NULL) {

$sizearr = getSizeCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy);

echo "[img][/img]";

}`

to the following:

`function getCustomImageURL($size, $width=NULL, $height=NULL, $cropw=NULL, $croph=NULL, $cropx=NULL, $cropy=NULL, $wm=true) {

global $_zp_current_image;

return $_zp_current_image->getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy, $wm);

}`

`function printCustomSizedImage($alt, $size, $width=NULL, $height=NULL, $cropw=NULL, $croph=NULL, $cropx=NULL, $cropy=NULL, $class=NULL, $id=NULL, $wm=true) {

$sizearr = getSizeCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy);

echo "[img][/img]";

}`

What this code does is that by default, when you use [b]getCustomImageURL()[/b] it will automatically watermark your image (this way your images are ALWAYS protected. If you want to turn it off (to maybe make a custom-sized thumbnail), just set the [b]8th[/b] parameter of the function to [b]false[/b]. However, it's the opposite for [b]getCustomAlbumThumb()[/b]. Because we have it explicitly get a thumb, we have $wm be false by default.

That should do it.

Member
Member
nathan   21-06-2006, 06:23
#33

This is a fairly lengthy hack. I'll take a look at seeing if there is a different way to do this. I tired my best to make the code small, and this is really a bit too much for what I was after.

I like this bit though:
`////////////////////////////////////////////////////////////////////////////////

// Watermark Hack

////////////////////////////////////////////////////////////////////////////////

$perform_watermark = zp_conf('perform_watermark');

$watermark_image = zp_conf('watermark_image');

if ($perform_watermark == true && $thumb == false && $_GET['wm'] == true) {

$watermark = imagecreatefrompng($watermark_image);

imagealphablending($watermark, false);

imagesavealpha($watermark, true);

$watermark_width = imagesx($watermark);

$watermark_height = imagesy($watermark);

// Position Overlay in Bottom Right

$dest_x = imagesx($newim) - $watermark_width;

$dest_y = imagesy($newim) - $watermark_height;

imagecopy($newim, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);

imagedestroy($watermark);

}

////////////////////////////////////////////////////////////////////`

Thanks for that.

Member
Member
nathan   21-06-2006, 06:25
#34

Sorry for a double post, but we might be able to get this included in the zenphoto project. That way, people won't have to edit ALL the files themselves. They won't have to do anything really.

I'll open a feature request in the bug tracker.

Member
Member
DarrellD   21-06-2006, 14:14
#35

Well, if this will be worked in "officially" it would be great if not only would we be able to specify the default watermark image in the config, but if we were also able to specify a different watermark image during runtime.

This would be useful, for example, if I wanted a default watermark on my bigger images (say it was a logo and my domain name), but then later on decide to watermark my thumbnails with just the logo. When I call the function to specify a thumbnail, I could just easily give it the name of the new watermark.

Member
Member
Daxeno   26-06-2006, 19:31
#36

This is still not in the Wiki.

Developer
Developer
trisweb   27-06-2006, 06:11
#37

Good point Daxeno. ;-)

Member
Member
Daxeno   27-06-2006, 08:45
#38

and it seems not working as well.

Member
Member
thinkdreams   27-06-2006, 13:52
#39

Dax-

I was able to get the antialiasing working on my site OK. What seems to not be working?

Thinkdreams.

Member
Member
thinkdreams   27-06-2006, 14:20
#40

In case you haven't seen it, http://www.thinkdreams.com/devzp is where my test site is at.

I used Nathan's original code, without the GameDudeX modifications (just haven't had time to integrate them yet).

Thinkdreams

Pages (4):    1 2 3 4   
  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.