Watermark is functionality for images of different formats, we usually use logo over images to secure from public use. If want to use water mark for different formats of images then go through the following code.
This php code is used for watermark for jpg,jpeg,png,PNG,bmp,BMP formats.
Here is code snippet.

                     $eof = substr(strrchr($_FILES['userfile']['name'], ‘.’), 1);
$new_name = ”;
if($eof==’png’ || $eof==’PNG’) {
$new_name = $destination.$_FILES['userfile']['name'].”.png”;
}
elseif($eof==’jpg’ || $eof==’jpeg’ || $eof==’JPG’ || $eof==’JPEG’) {
$new_name = $destination.$_FILES['userfile']['name'].”.jpg”;
}
elseif($eof==’gif’) {
$new_name = $destination.$_FILES['userfile']['name'].”.gif”;
}


                          $res= $this->watermark_image($destination.$file[‘name’], $new_name);
if($res)
{
//$demo_image = $new_name;
//var_dump($demo_image);die;
}

function watermark_image($oldimage_name, $new_image_name){
// global $image_path;
$image_path = “http://www.archstonedubai.com/demo/archstone/public/images/watermark.png”;
list($owidth,$oheight) = getimagesize($oldimage_name);
$data = getimagesize($oldimage_name);
$width = $data[0];
$height = $data[1];
//$width = $height = 300;
$im = imagecreatetruecolor($width, $height);
//////////////////////////
$eof = substr(strrchr($oldimage_name, ‘.’), 1);
$img_src = ”;
if($eof==’png’ || $eof==’PNG’) {
$img_src = imagecreatefrompng($oldimage_name);
}
elseif($eof==’jpg’ || $eof==’jpeg’ || $eof==’JPG’ || $eof==’JPEG’) {
$img_src = imagecreatefromjpeg($oldimage_name);
}
elseif($eof==’gif’) {
$img_src = imagecreatefromgif($oldimage_name);
}
//////////////////////////
///$img_src = imagecreatefromjpeg($oldimage_name);
imagecopyresampled($im, $img_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
$watermark = imagecreatefrompng($image_path);
list($w_width, $w_height) = getimagesize($image_path);
$pos_x = $width – $w_width;
$pos_y = $height – $w_height;
imagecopy($im, $watermark, $pos_x, $pos_y, 0, 0, $w_width, $w_height);
imagejpeg($im, $new_image_name, 100);
imagedestroy($im);
unlink($oldimage_name);
return true;
}


Above code is to show watermark over images of different formats as jpg,bmp and png

 

Leave a Reply

Your email address will not be published. Required fields are marked *