PHP Image watermarking script with png watermarking logo
Image watermarking script with png watermarking logo image file !! Use the logo in png format with tranparent background for smoother effects!!
<?php
function watermarkImage ($imagesource, $watermarkPath, $DestinationFile)
{
//scrpt edite by neodare@gmail.com with transparent png watermarking
$filetype = substr($imagesource,strlen($imagesource)-4,4);
$filetype = strtolower($filetype);
$watermarkType = substr($watermarkPath,strlen($watermarkPath)-4,4);
$watermarkType = strtolower($watermarkType);
if($filetype == “.gif”)
$image = @imagecreatefromgif($imagesource);
else
if($filetype == “.jpg” || $filetype == “jpeg”)
$image = @imagecreatefromjpeg($imagesource);
else
if($filetype == “.png”)
$image = @imagecreatefrompng($imagesource);
else
die();
if(!$image)
die();
if($watermarkType == “.gif”)
$watermark = @imagecreatefromgif($watermarkPath);
else
if($watermarkType == “.png”)
$watermark = @imagecreatefrompng($watermarkPath);
else
die();
if(!$watermark)
die();
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);
$startwidth = (($imagewidth - $watermarkwidth));
$startheight = (0);
imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
if ($DestinationFile < >”) {
imagejpeg ($image, $DestinationFile, 100);
} else {
header(’Content-Type: image/jpeg’);
imagejpeg($image, null, 100);
};
imagedestroy($image);
}
$SourceFile = “myimage.jpg”; //enter the location source image here
$DestinationFile = “newimage.jpg”; //enter the destination location of image here
$watermarkPath =”watermark.png”; //enter the watermarking logo images location here
watermarkImage ($SourceFile, $watermarkPath, $DestinationFile);
? >