Saturday, September 22, 2012

Water mark in PHP

Processing with image in PHP, Adding watermark is very help full. Add Image Watermark with original image is also help to protect our images here is my solution to Add Water Mark in PHP

Prepare an transparent image with exact same size of the original image. Transparent PNG with Text by overlap original image to create a final watermark added image.

// Original Image Path
$image= "images/original_image.jpg";  

header("Content-type: image/jpeg");
header("Content-Disposition: inline; filename=$image");

switch (TRUE) {
case stristr($image,'jpg') :
$photoImage = ImageCreateFromJPEG("$image");
case stristr($image,'gif') :
$photoImage = ImageCreateFromGIF("$image");
case stristr($image,'png') :
$photoImage = ImageCreateFromPNG("$image");

ImageAlphaBlending($photoImage, true); 

// Same Size PNG Watermark Image with Transparency
$logoImage = ImageCreateFromPNG("watermark_image.png"); 
$logoW = ImageSX($logoImage); 
$logoH = ImageSY($logoImage); 

// were you see the two 1's this is the offset from the top-left hand corner!
ImageCopy($photoImage, $logoImage, 1, 1, 0, 0, $logoW, $logoH); 

// if you want to save add the following line



No comments:

Post a Comment