• Subcribe to Our RSS Feed

[WaterMark] How To Add WaterMark Image Into Uploaded Image In Php

Nov 26, 2012   //   by admin   //   Other, PHP  //  No Comments

Hi Friends,
I did make a script for add water mark image into uploaded image.In this script you can upload image in .png,.jpg or .gif format and using .png watermark you can generate new image with watermark.
You can set you water mark in different position whatever you want.I will explain you how you can change position of watermark image.

First of all we can see the code for generate image with watermark.

<?php 
$watermark="uploads/watermark.png";									
 
if($imagetype == ".png"){
  $img=imagecreatefrompng("upload/data/yourimage.png");
}
elseif($imagetype == ".jpg"){
  $img=imagecreatefrompng("upload/data/yourimage.jpg");
}
elseif($imagetype == ".gif"){
   $img=imagecreatefrompng("upload/data/yourimage.gif");
}
else{
  $skipper= "1";	
}
if($skipper!= "1")
{
$img_width=imagesx($img);
 
$img_height=imagesy($img);
 
$watermark=imagecreatefrompng($watermark);
 
$watermark_width=imagesx($watermark);
 
$watermark_height=imagesy($watermark);
 
$image=imagecreatetruecolor($img_width, $watermark_height);
 
imagealphablending($image, false);
 
$dest_x=$img_width-5;
 
$dest_y=$img_height-5;
 
imagecopy($img,$watermark,$dest_x,$dest_y,0,0,$img_width,$watermark_height);                    imagesavealpha($img, true);
}
?>

Using above code you can generate the image with watermarks.you can put watermark to different places
using imagecopy() function.you have to pass different argument for different position for more detail about argument you can read Php Manual.

All the Best.
Thanks.

Leave a comment

*