View Full Version : gd image to watermark image?

03-24-2003, 09:44 PM
is there a method in gd to change an image into a watermark image?

i'm wishing to create an automated process where and image would be automatically converted to 20% opacity against a white matte.

03-24-2003, 10:01 PM
you want to iterate through the image pixel by pixel and then imagecopymerge a sampling over a plain white base

$resource = 'whatever.jpg';
$opacity = 20;
$siz = getimagesize($resource);
$basei = imagecreatefromjpeg($resource);
$newi = imagecreatetruecolor($siz[0],$siz[1]);
$whit = imagecolorallocate($newi, 255, 255, 255);
for($dy = 0; $dy < $siz[1]; $dy++)
for($dx = 0; $dx < $siz[0]; $dx++)
imagecopymerge($newi, $basei, $dx, $dy, $dx, $dy, 1, 1, $opacity);
imagejpeg($newi, 'folder/save.jpg', 85);

fly typed so will probably parse bad, should point you in the right direction though.
subnote - GD2 functions used.

edit - you wouldn't need to iterate really - lose the for loops and just use

imagecopymerge($newi, $basei, 0, 0, 0, 0, $siz[0], $siz[1], $opacity);

03-24-2003, 10:56 PM

11-03-2003, 02:48 AM
This is very cool...

But is there a way to embed the watermark on the top of the image, you know like to have a JPG with a watermark on the top...

And also be able to control the quality and opacity based on the color that we don't want to be visible...

Also I forgot I have GD. 1.6 so imagecreate() is what works not imagecreateTrueColor()

Please help
Any ideas?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum