I have a function that adds a watermark on a photo after it was uploaded and i don’t understand why I can not apply the watermark:
/********************/
/*****WATERMARK*****/
/********************/
function doWatermark($calePoza, $caleLogo, $pozitionare = 'centru') {
$watermark = imagecreatefrompng($caleLogo);
$filetype = substr($calePoza,strlen($calePoza)-4,4);
$filetype = strtolower($filetype);
if($filetype == ".gif") {$photo = imagecreatefromgif($calePoza);}
if($filetype == ".jpg") {$photo = imagecreatefromjpeg($calePoza);}
if($filetype == "jpeg") {$photo = imagecreatefromjpeg($calePoza);}
if($filetype == ".png") {$photo = imagecreatefrompng($calePoza);}
imagealphablending($photo, true);
$widthWatermark = imagesx($watermark);
$heightWatermark = imagesy($watermark);
$widthPhoto = imagesx($photo);
$heightPhoto = imagesy($photo);
if ($pozitionare == 'centru') {
$xLogoPosition = ceil(($widthPhoto - $widthWatermark) / 2);
$yLogoPosition = ceil(($heightPhoto - $heightWatermark) / 2);
} else {
$xLogoPosition = $widthPhoto - $widthWatermark - 10;
$yLogoPosition = $heightPhoto - $heightWatermark - 10;
}
$result = imagecopy($photo, $watermark, $xLogoPosition, $yLogoPosition, 0, 0, $widthWatermark, $heightWatermark);
if($filetype == ".gif") {header('Content-type: image/gif');imagegif($photo, $calePoza, 100); }
if($filetype == "jpeg") {header('Content-type: image/jpeg');imagejpeg($photo, $calePoza, 100);}
if($filetype == ".jpg") {header('Content-type: image/jpeg');imagejpeg($photo, $calePoza, 100);}
if($filetype == ".png") {header('Content-type: image/png');imagepng($photo, $calePoza, 100);}
imagedestroy($photo);
return $result;
}