我正尝试在watermark
中以编程方式在图片上创建PHP
。图片由users
上传,可能具有不同的尺寸。我在创建watermark
时所做的是:
$stamp = imagecreatefrompng('stamp381x387.png');
$ext = substr(strrchr($_GET['src'], '.'), 1);
if ($ext == 'png') {
$im = imagecreatefrompng($_GET['src']);
} else if ($ext == 'jpg') {
$im = imagecreatefromjpeg($_GET['src']);
}
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 0;
$marge_bottom = 0;
$sx = imagesx($stamp); //width
$sy = imagesy($stamp); //height
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($im, $stamp, (imagesx($im) - $sx ) / 2, (imagesy($im) - $sy) / 2, 0, 0, imagesx($stamp), imagesy($stamp));
// Output and free memory
if ($ext == 'png') {
header('Content-type: image/png');
imagejpeg($im);
imagedestroy($im);
} else if ($ext == 'jpg') {
header('Content-type: image/jpeg');
imagejpeg($im);
imagedestroy($im);
}
如何在所有images
上统一?有什么帮助吗?
答案 0 :(得分:0)
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
这是使用PHP在图像上添加水印的一个很好的示例 - http://php.net/manual/en/image.examples-watermark.php