At 11:32 AM -0400 8/4/07, Tom Ray [Lists] wrote:
I've been learning how to use PHP with the GD Library and I've
managed to learn quite a bit. I can upload, resize, create
thumbnails and I'm even able to create "security code" images for
forms. My question is how do I create a Watermark on the image? I
want something transparent but still visible enough to see the
copyright and the website. I want to put it in the center of the
image. I would use a non-water marked image and when it's called on
(depending on viewing size) I want the water mark to be added.
How would one go about doing that?
Tom:
I just combine images -- it's simple.
Here's an example:
http://www.webbytedd.com/b/watermark/
Refresh and the watermark position will move.
Here's the code (refreshing will shift the watermark around):
<?php
$place = "c";
$original=imagecreatefromjpeg("mydog.jpg");
$watermark=imagecreatefrompng("copyright.png");
$osx=imagesx($original);
$osy=imagesy($original);
$wsx=imagesx($watermark);
$wsy=imagesy($watermark);
$place = rand(1,5);
switch ($place)
{
case 1: //"c":
imagecopy($original, $watermark, ($osx-$wsx)/2,
($osy-$wsy)/2, 0, 0, $wsx, $wsy); //center works
break;
case 2: //"nw":
imagecopy($original, $watermark,0, 0, 0, 0, $wsx, $wsy); //
upper left works
break;
case 3: //"sw":
imagecopy($original, $watermark, 0, ($osy-$wsy), 0, 0, $wsx,
$wsy); // lower right works
break;
case 4: //"ne":
imagecopy($original, $watermark, ($osx-$wsx), 0, 0, 0, $wsx,
$wsy); // upper left works
break;
case 5: //"se":
imagecopy($original, $watermark, ($osx-$wsx), ($osy-$wsy), 0,
0, $wsx, $wsy); // lower right works
break;
}
imagepng($original, "trans.png");
?>
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php