Center watermark on image

php

Solution

replace

// destination x and y 
   $imageWidth-$logoWidth, $imageHeight-$logoHeight,

with

// destination x and y 
   ($imageWidth-$logoWidth)/2, ($imageHeight-$logoHeight)/2

,

Problem

I need to add watermark on image. I have solved using this code, work well, but image is positioned on left/bottom corner. How to set to center watermark on image center? ``` $img = 'test.jpg'; // Load the image where the logo will be embeded into $image = imagecreatefromjpeg($img); // Load the logo image $logoImage = imagecreatefrompng("watermark.png"); imagealphablending($logoImage, true); // Get dimensions $imageWidth=imagesx($image); $imageHeight=imagesy($image); $logoWidth=imagesx($logoImage); $logoHeight=imagesy($logoImage); // Paste the logo imagecopy( // destination $image, // source $logoImage, // destination x and y $imageWidth-$logoWidth, $imageHeight-$logoHeight, // source x and y 0, 0, // width and height of the area of the source to copy $logoWidth, $logoHeight); // Set type of image and send the output header("Content-type: image/png"); imagePng($image); // Release memory imageDestroy($image); imageDestroy($imageLogo); ```

Original source