Hello. There is a function of overlaying a watermark on the uploaded photo:

function watermark($file, $watermark) { if (empty($file) || empty($watermark)) { return false; } $wh = getimagesize($watermark); $fh = getimagesize($file); $rwatermark = imagecreatefrompng($watermark); $rfile = imagecreatefromjpeg($file); imagecopy($rfile, $rwatermark, $fh[0] - $wh[0], $fh[1] - $wh[1], 0, 0, $wh[1], $wh[1]); imagejpeg($rfile, $file, '80'); imagedestroy($rwatermark); imagedestroy($rfile); return true; } 

Photo upload code:

 foreach ($_FILES['file']['name'] as $k => $f) { if (!$_FILES['file']['error'][$k]) { if (is_uploaded_file($_FILES['file']['tmp_name'][$k])) { $newfile = "$imgDir/" . $_FILES['file']['name'][$k]; if (move_uploaded_file($_FILES['file']['tmp_name'][$k], $newfile)) { watermark($newfile, './water.png'); $fsave = $_FILES['file']['name'][$k]; header("Location: /index.php"); } } } } 

So, the watermark now falls in the lower right corner. How to make a watermark overlay in the center of the uploaded photo? The size of the uploaded photo is fixed - 240x320.

I would be grateful for any useful information.

    1 answer 1

    Thank you for your attention)) Found a solution:

      imagecopy($rfile, $rwatermark, imagesx($rfile) - $sx - $marge_right, imagesy($rfile) - $sy - $marge_bottom, 0, 0, imagesx($rwatermark), imagesy($rwatermark)); 
    • From the code it is not clear where the $sx , $marge_right , $sy and $marge_bottom . It is also not entirely clear why to call imagesx and imagesy , if in the original code the sizes of the images were already defined. - newman pm