Problem:
Users need to upload images to a website and have a watermark (logo) added to them. The watermark should be placed prominently, such as in a corner where it will be visible.
Solution:
To add a watermark to images uploaded to a PHP website, you can use the following steps:
<code class="php">// Load the stamp (watermark) and the photo to be watermarked $stamp = imagecreatefrompng('stamp.png'); $im = imagecreatefromjpeg('photo.jpeg'); // Set margins for the stamp and get its dimensions $marge_right = 10; $marge_bottom = 10; $sx = imagesx($stamp); $sy = imagesy($stamp); // Calculate the position of the stamp on the photo $x = imagesx($im) - $sx - $marge_right; $y = imagesy($im) - $sy - $marge_bottom; // Copy the stamp onto the photo imagecopy($im, $stamp, $x, $y, 0, 0, $sx, $sy); // Output the watermarked image and free memory header('Content-type: image/png'); imagepng($im); imagedestroy($im);</code>
This code snippet can be integrated into your PHP website to automatically add a watermark to uploaded images.
以上是如何使用PHP為圖片添加浮水印?的詳細內容。更多資訊請關注PHP中文網其他相關文章!