What is the best way to position a watermark at the bottom center of an image when creating a thumbnail in PHP?
To position a watermark at the bottom center of an image when creating a thumbnail in PHP, you can calculate the x-coordinate by subtracting the watermark width from the image width and dividing by 2. For the y-coordinate, you can subtract the watermark height from the image height. Then, you can use the imagecopy() function to overlay the watermark onto the image at the calculated coordinates.
// Load the original image and watermark
$original_image = imagecreatefromjpeg('original.jpg');
$watermark = imagecreatefrompng('watermark.png');
// Get the dimensions of the original image and watermark
$original_width = imagesx($original_image);
$original_height = imagesy($original_image);
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
// Calculate the coordinates for the watermark at the bottom center
$x = ($original_width - $watermark_width) / 2;
$y = $original_height - $watermark_height;
// Overlay the watermark onto the original image
imagecopy($original_image, $watermark, $x, $y, 0, 0, $watermark_width, $watermark_height);
// Output the image with the watermark
header('Content-Type: image/jpeg');
imagejpeg($original_image);
// Free up memory
imagedestroy($original_image);
imagedestroy($watermark);