// Load the image $img = imagecreatefromjpeg('photo.jpg'); // Create a watermark image $watermark = imagecreatefrompng('watermark.png'); // Set the watermark opacity imagealphablending($watermark, false); imagesavealpha($watermark, true); $opacity = 50; imagefilter($watermark, IMG_FILTER_COLORIZE, 0, 0, 0, 127 - $opacity * 1.27); // Position the watermark $padding = 10; $watermark_x = imagesx($img) - imagesx($watermark) - $padding; $watermark_y = imagesy($img) - imagesy($watermark) - $padding; // Merge the watermark and the image imagecopy($img, $watermark, $watermark_x, $watermark_y, 0, 0, imagesx($watermark), imagesy($watermark)); // Save the image with the watermark imagejpeg($img, 'photo_with_watermark.jpg', 100); // Free up memory imagedestroy($img); imagedestroy($watermark);
// Load the image $img = new Imagick('photo.jpg'); // Create a watermark image $watermark = new Imagick('watermark.png'); // Set the watermark opacity $opacity = 50; $watermark->setImageOpacity(1.0 - $opacity / 100); // Position the watermark $padding = 10; $watermark_x = $img->getImageWidth() - $watermark->getImageWidth() - $padding; $watermark_y = $img->getImageHeight() - $watermark->getImageHeight() - $padding; // Merge the watermark and the image $img->compositeImage($watermark, Imagick::COMPOSITE_OVER, $watermark_x, $watermark_y); // Save the image with the watermark $img->writeImage('photo_with_watermark.jpg'); // Free up memory $img->destroy(); $watermark->destroy();In conclusion, PHP Image water is a great technique to add watermarks to images in PHP. There are several package libraries available for this purpose, including GD Library and Imagick. Both libraries offer a wide range of features and functionalities to add watermarks to images in PHP.