Social Networks

If you are a professional or a newbie photographer you will probably want to protect your photos from being stolen and used for free. Using PHP you can create different types of watermarks on all of your images.
One common requirement – Let’s suppose that you’ve just been given few screen-shots from the upcoming product and You want to share your screenshots, but credit has to be given to your company. In this requirement you can use text or company logo watermark to protect your screen-shots.


Today is interesting tutorial for PHP – how to generate watermark image using PHP. In this post 9lesson coded two functions such as watermark_text() and watermark_image() to generate text and images watermarks on images. Integrate this to your web project upload image system and produce copyright photos.

Download Source

Watermark with Text – watermark_text()
Text watermark function, here you have to configure font source, size and text.



$font_path = &quot;GILSANUB.TTF&quot;; // Font file<br />
$font_size = 30; // in pixcels<br />
$water_mark_text_2 = &quot;9lessons&quot;; // Watermark Text<br />
<br />
function watermark_text($oldimage_name, $new_image_name)<br />
{<br />
global $font_path, $font_size, $water_mark_text_2;<br />
list($owidth,$oheight) = getimagesize($oldimage_name);<br />
$width = $height = 300; <br />
$image = imagecreatetruecolor($width, $height);<br />
$image_src = imagecreatefromjpeg($oldimage_name);<br />
imagecopyresampled($image, $image_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);<br />
$blue = imagecolorallocate($image, 79, 166, 185);<br />
imagettftext($image, $font_size, 0, 68, 190, $blue, $font_path, $water_mark_text_2);<br />
imagejpeg($image, $new_image_name, 100);<br />
imagedestroy($image);<br />
unlink($oldimage_name);<br />
return true;<br />

Watermark with Image – watermark_image()
Image watermark function, here you have to configure image water mark source



$image_path = "9lesson.png";

function watermark_image($oldimage_name, $new_image_name)
global $image_path;
list($owidth,$oheight) = getimagesize($oldimage_name);
$width = $height = 300;
$im = imagecreatetruecolor($width, $height);
$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);
return true;

Image Form
Contains simple PHP and HTML form submit code. Here HTML form sending post request.

$demo_image= "";
if(isset($_POST['createmark']) and $_POST['createmark'] == "Submit")
$path = "uploads/";
$valid_formats = array("jpg", "bmp","jpeg");
$name = $_FILES['imgfile']['name'];
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats) && $_FILES['imgfile']['size'] <= 256*1024)
$upload_status = move_uploaded_file($_FILES['imgfile']['tmp_name'], $path.$_FILES['imgfile']['name']);
$new_name = $path.time().".jpg";
// Here you have to user functins watermark_text or watermark_image
if(watermark_text($path.$_FILES['imgfile']['name'], $new_name))
$demo_image = $new_name;
$msg="File size Max 256 KB or Invalid file format.";
// HTML Code
<form name="imageUpload" method="post" enctype="multipart/form-data" >
Upload Image
Image :<input type="file" name="imgfile" /><br />
<input type="submit" name="createmark" value="Submit" />
echo '<img src="'.$demo_image.'" />';
None found.
  1. If you are looking for PHP and Jquery and for developing web application easy and with creativity web application… get fully supportable developer for Jquery. get upload pictures with ajax/jQuery and PHP without refreshing the page from Our services……..

Leave a Reply

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

Allowed Tags:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>