Get complete CodeIgniter blog project for free!

Downloaded more than 161 times, this is full project must-study for serious developers!

By submitting this form, you agree to our Terms of Service and Privacy Policy.

Image watermark in PHP

Watermark is the most using method to copyright images. You can protect your websites images using image watermark. PHP helps to create watermark automatically when you upload an image in your website and when you execute this image in your website. You don't need to do that manually PHP will do that for you. Let's see how PHP will do that for you. We are going to create a PHP script for that and we will use PHP imagecopymerge() function for do that. create a file name as watermark.php and write down this code into the script.



header('content-type: image/jpeg');
$src = $_GET['src'];
$path = pathinfo($src);
$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
if ($path['extension']=='png')
$image = imagecreatefrompng($src);
else if ($path['extension']=='jpg'||$path['extension']=='jpeg')
$image = imagecreatefromjpeg($src);
$size = getimagesize($_GET['src']);
$dest_x = $size[0] - $watermark_width-10;
$dest_y = $size[1] - $watermark_height-10;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 50);

We need a watermark image for this script, this image will show in every Image as a watermark. We declared it on this script name as watermark.png. In this script we will get image using $_GET['src'] get method then merge this image using imagecopymerge() function. When this script works then all images will merge into a single image and execute as a new image with image watermark.

When we execute an image file into watermark format then we need to call image address like this 
If you do tasks before correctly then this script will execute image with watermark. this script will show image watermark via watermark.php script.

You can protect your website images and confirm your authority using this watermark method. It's most popular method for websites. Hope you can understand this tutorial correctly. If you face any problem you can comment here.

Search on PHPAns
Subscribe to PHPAns
Join with our 32000+ subscribers and get our latest articles in your email inbox for free.
Delivered by FeedBurner
We always respect your privacy and take protecting it seriously.
Connect Social With PHPAns