PHP基础-如何给图片添加水印

系统目录下,新建images文件夹,放入图片

cat.jpeg
cat.jpeg
watermark
watermark
<html>
<head>
    <title>使用PHP给图片加水印</title>
</head>
<body>
    <span>虾米大王使用PHP给图片加水印</span>
    <hr>
    <table>
        <tr>
            <td>原图:</td>
            <td>加水印后的图片:</td>
        </tr>
        <tr>
            <td><img src="images/cat.jpeg" width="600" height="600"></td>
            <td><img src="images/cat_water.jpeg" width="600" height="600"></td>
        </tr>
    </table>
</body>
</html>

<?php
    $image = imagecreatefromjpeg('images/cat.jpeg');
    $watermark = imagecreatefrompng('images/gua.png');
    $width = imagesx($watermark);
    $height = imagesy($watermark);
    imagecopyresampled($image,$watermark,60,250,0,0,
        ($width * 0.3),($height * 0.3),$width,$height);
    imagejpeg($image,'images/cat_water.jpeg');  //保存图片
    imagedestroy($image);
    imagedestroy($watermark);
?>

猜你喜欢

转载自blog.csdn.net/modern358/article/details/89512909