PHP GD watermark on Images


 

PHP GD watermark on Images

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

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

<?php

$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");

imagejpeg($image);

imagedestroy($image);

imagedestroy($watermark);

?>

After running the program you will get the following output

Ads