How to watermark images using Wide Image PHP library

If you have a website for products which are very competitive in nature and you don’t want your competitors to steal your images online then you can watermark your images with your logo or any text which would identify the true owner of those images and discredit those who try to steal them in the first place.

You can use simple PHP code to create a watermarked image but in this example we will be using Wide Image PHP library for image manipulation to create one. Download Wide Image from here. Unzip it and copy the lib folder to where your website code resides.

Next open MS Paint or any other image editing software and create your logo or text based image. For this example I create a text based image by simply writing my name and saving it as a PNG file.

Text  based image

We will be applying this watermark on the following image

non-watermarked-image

We now add the following PHP code

// Path to the WideImage.php file in the lib folder
require('lib/WideImage.php');

// Load the actual product image on which we want to apply the watermark
$image = WideImage::load('non-watermarked-image.jpg');

// Load the watermarked image 
$watermark = WideImage::load('my-logo.png');

// Apply the watermark to the product image
$newimage = $image->merge($watermark, '10%', '40%', 10);

// The 2nd parameter is the x position of the watermarked image
// The 3rd parameter is the y position of the watermarked image
// The 4th parameter is the opacity level of the watermarked image

// Save the watermarked image 
$newimage->saveToFile('watermarked-image.jpg');

After running the above code I am left with the watermarked image

watermarked-image

Hope the above helps.

Please follow and like us:
error

Be the first to comment

Leave a Reply

Your email address will not be published.