What are the potential issues when using a PNG watermark on a JPEG image in PHP?

When using a PNG watermark on a JPEG image in PHP, the potential issue is that the transparency of the PNG watermark may not display correctly on the JPEG image. To solve this issue, you can merge the PNG watermark with the JPEG image using imagecopymerge() function in PHP, which will preserve the transparency of the PNG watermark.

// Load the JPEG image
$jpeg = imagecreatefromjpeg('image.jpg');

// Load the PNG watermark with transparency
$watermark = imagecreatefrompng('watermark.png');

// Get the dimensions of the JPEG image and PNG watermark
$jpegWidth = imagesx($jpeg);
$jpegHeight = imagesy($jpeg);
$watermarkWidth = imagesx($watermark);
$watermarkHeight = imagesy($watermark);

// Merge the PNG watermark onto the JPEG image with transparency
imagecopymerge($jpeg, $watermark, $jpegWidth - $watermarkWidth, $jpegHeight - $watermarkHeight, 0, 0, $watermarkWidth, $watermarkHeight, 100);

// Output the final image
header('Content-Type: image/jpeg');
imagejpeg($jpeg);

// Free up memory
imagedestroy($jpeg);
imagedestroy($watermark);