Creating a watermark for normal individuals is not an easy task. For a professional designer, it is an easier task to do. Let’s create a system that will help you create an image with a watermark in just a minute of time using PHP. We decide to use PHP as it is one of the most popular programming language in the context of Nepal.
Doing it on the local machine requires xampp or wamp or lamp or mamp. The purpose of using one of these is they provide PHP and Apache server to work locally.
Step 1: Loading the images
$logo = imagecreatefrompng('logo.png'); $image = imagecreatefrompng('image.png');
Step 2: Getting the height and width along with the margins
$margin_right = 500; $margin_bottom = 350; $img_width = imagesx($logo); $img_height = imagesy($logo);
Step 3: Positioning the image and aligning the logo as per the calculation
imagecopy($image, $logo, imagesx($image ) - $img_width - $margin_right, imagesy($image) - $img_height - $margin_bottom, 0, 0, imagesx($logo), imagesy($logo));
here we are positioning the image that we want to use as a watermark over another.
Step 4: Output and freeing memory
header('Content-type: image/png'); imagepng($image); imagedestroy($image);
here we are displaying the output and freeing the memory that has been held during the operation.
Images that have been used: