Share on Google+Share on Google+

PHP GD watermark on Images

This example shows how Add to watermark image in php gd.


$main_img = "main.jpg";

$watermark_img = "RI-Logo.jpg";

$padding = 50;

$opacity = 30;

$watermark = imagecreatefromjpeg($watermark_img);

$image = imagecreatefromjpeg($main_img);

if(!$image || !$watermark) die("Error: main image or watermark could not be loaded!");

$watermark_size = getimagesize($watermark_img);

$watermark_width = $watermark_size[0];

$watermark_height = $watermark_size[1];

$image_size = getimagesize($main_img);

$dest_x = $image_size[0] - $watermark_width - $padding;

$dest_y = $image_size[1] - $watermark_height - $padding;

imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $opacity);

header("content-type: image/jpeg");





After running the program you will get the following output


Posted on: November 17, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.