<?php


function WaterMark($img_src){


$i = strrpos($img_src,".");
if (!$i) { return ""; }
$l = strlen($img_src) - $i;
$ext = substr($img_src,$i+1,$l);
$extension = getExtension($img_src);
$extension = strtolower($extension);


	
// Load the stamp and the photo to apply the watermark to
if (file_exists('../img/watermark2.png')) {
	//echo 'saad';
}

@$stamp = imagecreatefrompng(__DIR__ .'/../../img/watermark1.png');
@$stamp2 = imagecreatefrompng(__DIR__ .'/../../img/watermark2.png');

if ($stamp !== false) {
    // إعادة حفظ الصورة لتكون بدون ملف تعريف لوني
    imagepng($stamp, '../img/watermark.png');
	@$stamp = imagecreatefrompng(__DIR__ .'/../../img/watermark1.png');
	@$stamp2 = imagecreatefrompng(__DIR__ .'/../../img/watermark2.png');


} 



//$stamp2 = imagecreatefrompng('../../img/watermark2.png');
$im = imagecreatefromwebp("$img_src");	



$marge_right = 0;
$marge_bottom = 0;
$sx = imagesx($stamp2);
$sy = imagesy($stamp2);
$imgx = imagesx($im);
$imgy = imagesy($im);
$centerX=round($imgx/2-$sx/2);
$centerY=round($imgy/2-$sy/2);

// Copy the stamp image onto our photo using the margin offsets and the photo 
// width to calculate positioning of the stamp. 
imagecopy($im, $stamp, 0,0, 0, 0, imagesx($stamp), imagesy($stamp));
imagecopy($im, $stamp2, $centerX,$centerY, 0, 0, imagesx($stamp2), imagesy($stamp2));

// Output and free memory

imagewebp($im,"$img_src",80);

}
?>