All you have to do is just copy and paste the code below on to a file name in your localhost.
Take two images any of .JPG OR .PNG OR .GIF
Here for orginal image i have given the name as originalImage.jpg
For water mark image i have given the name as watermark.jpg
So all you have to do is create a PHP file of your desired name then bring two images namely originalImage.jpg and watermark.jpg on to the same directory where the PHP file is created.
Note:-Your GD library must be enabled
DONT EDIT ANYTHING BELOW IF YOU ARE NOT FAMILIAR WITH PHP
< ?php
balu::GDversion();
$stamp = new balu(‘originalImage.jpg’, ‘watermark.jpg’, ‘balututorialz.tk_’);
$stamp->stampPicture();
class balu{
// class variables
private $fileHandle = null;
private $newPictureName = null;
private $pictureInfo = null;
private $pictureName = null;
private $prefix = null;
private $stampInfo = null;
private $stampName = null;
private $stampXpos = null;
private $stampYpos = null;
function __construct($picture, $stamp, $prefix = ‘balututorialz.tk_’){
$this->pictureName = $picture; // original picture to place stamp/watermark on
$this->stampName = $stamp; // stamp/watermark picture
$this->prefix = $prefix; // prefix of new stamped picture
}// end of construct
public static function GDversion(){
// GD 2.0.28 or newer is recommended version to use
// http://www.php.net/manual/en/function.gd-info.php
var_dump(gd_info()); // dump information about your GD version
return true;
}// end of GDversion
private function openImage($fileName, $type){
// open picture with correct image function. Add more types if needed.
// GIF: http://php.net/manual/en/function.imagecreatefromgif.php
// JPG/JPEG: http://php.net/manual/en/function.imagecreatefromjpeg.php
// PNG: http://php.net/manual/en/function.imagecreatefrompng.php
switch ($type){
case 1: // GIF
$this->fileHandle = imagecreatefromgif($fileName);
break;// case 1
case 2: // JPG/JPEG
$this->fileHandle = imagecreatefromjpeg($fileName);
break;// case 2
case 3: // PNG
$this->fileHandle = imagecreatefrompng($fileName);
break;// case 3
default:
die(‘Unsupported filetype: ‘.$fileName);
}
return $this->fileHandle;
}// end of openImage
public function stampPicture(){
// get picture info such as width, height and extension
// http://php.net/manual/en/function.getimagesize.php
$this->pictureInfo = getimagesize($this->pictureName) or die(‘Error getting picture info. Double check file path.’);
$this->stampInfo = getimagesize($this->stampName) or die(‘Error getting stamp info. Double check file path.’);
// open images with class method openImage()
$this->pictureFile = $this->openImage($this->pictureName, $this->pictureInfo[2]);
$this->stampFile = $this->openImage($this->stampName, $this->stampInfo[2]);
// position the stamp in the lower right corner
$this->stampXpos = $this->pictureInfo[0] – $this->stampInfo[0] – 15; // width – width – margin
$this->stampYpos = $this->pictureInfo[1] – $this->stampInfo[1] – 15; // height – height – margin
// set a new name for the stamped picture and keep the original picture intact
$this->newPictureName = $this->prefix.$this->pictureName;
// alpha blending: http://php.net/manual/en/function.imagealphablending.php
imagealphablending($this->pictureFile, true);
// merge the two images: http://php.net/manual/en/function.imagecopymerge.php
imagecopymerge($this->pictureFile, $this->stampFile, $this->stampXpos, $this->stampYpos, 0, 0, $this->stampInfo[0], $this->stampInfo[1], 100);
// output the stamped image as GIF, JPG/JPEG or PNG. Add more types if needed.
// default type is the same as the original file
// GIF: http://php.net/manual/en/function.imagegif.php
// JPG/JPEG: http://php.net/manual/en/function.imagejpeg.php
// PNG: http://php.net/manual/en/function.imagepng.php
switch ($this->pictureInfo[2]){
case 1: // GIF
imagegif($this->pictureFile, $this->newPictureName);
break;// case 1
case 2:// JPG/JPEG
imagejpeg($this->pictureFile, $this->newPictureName);
break;// case 2
case 3: // PNG
imagepng($this->pictureFile, $this->newPictureName);
break;// case 3
default:
die(‘Unsupported filetype: ‘.$fileName);
}
return true;
}// end of stampPicture
function destruct(){
unset($fileHandle, $newPictureName, $pictureInfo, $pictureName, $prefix, $stampInfo, $stampName, $stampXpos, $stampYpos);
}// end of destruct
}// end of class
//mistonline.in
?>
Incoming search terms:
- gd library watermark (5)
- php gd create image from filehandle (3)
- gd library add water stamp (2)
- inurl:loginscript php (2)
- error getting picture info double check file path (2)
- water mark in php (2)
- php watermark gd (2)
- php image thumb with water sign (2)
- php5 watermark (2)
- php watermark GD Library (1)
- php watermark lib (1)
- php watermark name (1)
- php watermarking (1)
- php watermark curl (1)
- php water image function (1)
- php stamp script (1)
- php stamp all images with filename (1)
- php gd library water marking (1)
- php gd tutorial watermark (1)
- php image water (1)
- php image water marking script (1)
- php image watermark gd library (1)
- PHP Image Watermark Using GD Library# (1)
- php image whater library (1)
- php images mark (1)
- php jpeg marking (1)
- php jquery image stamp (1)
- php put stamp on png (1)
- php putcsv (1)
- putcsv mysql (1)
- script php auto stamp image (1)
- watermark image using php gd library (1)
- watermark images in database php (1)
- watermark images using jquery example (1)
- watermark images using php5 and gd library (1)
- watermark images with php5 and GD (1)
- Watermark Images with select text Using PHP and GD Library (1)
- watermark jpg GD php (1)
- watermark on php using jquery (1)
- watermark php gd (1)
You will also be interested in ,
- Creating An Image Using PHP
- Finding The Size Of Images Using Javascript
- Date in title bar using php
- How to get the IP address of the visitor with PHP?
- Append data to a text file using php
- Apache AddHandler application/x-httpd-php not working?
- Login to yahoo using cUrl in php
- Add rounded edge or corner images using php
- Reading a particular line in a text file and replace it with another string using php
- Email address validation using php

