Hi, Guest ~ Login or Register

Watermarking

Watermarking

Listed In PHP and MySQL » Images and GD — Viewing Full Tutorial
Isn't it such a pain when you have a lot of work to do in Photoshop and don't have the time? Who wants to watermark 1000 images time after time when you can make one watermarking image and do the rest with a classy PHP script?

Step 1
Make yourself a watermark image in your favourite imaging program. Mine is Photoshop, and then make the backtounr transparent. Save it as watermark.png.

Step 2
In your favourite webpage editing program, mine is Dreamweaver, make yourself a new file called image.php, and then paste in this code:if(!$_GET['src']) {
exit("No source image, watermarking cancelled.");
}

header('Content-type: image/png');
$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);

$image = imagecreatetruecolor($watermark_width, $watermark_height);

if(eregi('.gif',$_GET['src'])) {

$image = imagecreatefromgif($_GET['src']);
}

elseif(eregi('.jpeg',$_GET['src'])||eregi('.jpg',$_GET['src'])) {

$image = imagecreatefromjpeg($_GET['src']);
}

elseif(eregi('.png',$_GET['src'])) {
$image = imagecreatefrompng($_GET['src']);

}
else {

exit("Your image is not a gif, jpeg or png image. Sorry..");

}

$size = getimagesize($_GET['src']);

$dest_x = $size[0] - $watermark_width - 10;

$dest_y = $size[1] - $watermark_height - 10;

imagecolortransparent($watermark,imagecolorat($watermark,0,0));

imagecopyresampled($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $watermark_width, $watermark_height);
imagepng($image);
imagedestroy($image);
imagedestroy($watermark);

This basically gets the extension, ?src= off the URL and grabs the image. If it's not .jpeg, .gif or .png then it says
sorry and exits PHP. Else it adds the watermark on top of the image and then displays it.

How do you make it work?

Go to your image.php and add the ?src= extension pointing to the image you'd like to watermark.

Working Beta

  1. The Forums
    These are mostly functional. If you see any weird bugs, post a thread about it and an administrator will do something.
  2. Tutorial Writing
    You can now submit tutorials to the brand new management system.
  3. Tutorials Home
    View tutorials by categories and search for them here.
  4. Shoutbox
    See below. Registered users only!

Register

Newest User

Say hi to Lirette25! Lirette25 joined on Monday, 14th July.

Sponsor

Check out Next day fake id

Shoutbox