Add watermark on image using php


Check below code for insert watermark image on your particular image.

It will be display watermark image over the original image in center.

header('content-type: image/jpeg');
$watermark = imagecreatefrompng('watermark.png');
// getting dimensions of watermark image
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image_path = 'original_image.jpg';
$image = imagecreatefromjpeg($image_path);
$orig_img_size= getimagesize($image_path); // getting the dimensions of original image

$dest_x = $orig_img_size[0]/2 - $watermark_width/2; // set width of watermark to display in center
$dest_y =$orig_img_size[1]/2 - $watermark_height/2; // set height of watermark to display in center

imagealphablending($image, true);
imagealphablending($watermark, true);
imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);

Advertisements
Posted in php

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s