如何在PHP中(使用GD)在已重新采样的图像上覆盖水印?
以下是我当前的代码:如何在PHP中(使用GD)在已重新采样的图像上覆盖水印?,php,image,gd,watermark,Php,Image,Gd,Watermark,以下是我当前的代码: define('IMG_WIDTH', (isset ($_GET['width'])) ? (int) $_GET['width'] : 99); define('IMG_HEIGHT', (isset ($_GET['height'])) ? (int) $_GET['height'] : 75); $image = imagecreatefromjpeg($_GET['image']); $origWidth = imagesx($image);
define('IMG_WIDTH', (isset ($_GET['width'])) ? (int) $_GET['width'] : 99);
define('IMG_HEIGHT', (isset ($_GET['height'])) ? (int) $_GET['height'] : 75);
$image = imagecreatefromjpeg($_GET['image']);
$origWidth = imagesx($image);
$origHeight = imagesy($image);
$croppedThumb = imagecreatetruecolor(IMG_WIDTH, IMG_HEIGHT);
if ($origWidth > $origHeight)
{
$leftOffset = ($origWidth - $origHeight) / 2;
imagecopyresampled($croppedThumb, $image, 0, 0, $leftOffset, 0, IMG_WIDTH, IMG_HEIGHT, $origHeight, $origHeight);
}
else
{
$topOffset = ($origHeight - $origWidth) / 2;
imagecopyresampled($croppedThumb, $image, 0, 0, 0, $topOffset, IMG_WIDTH, IMG_HEIGHT, $origWidth, $origWidth);
}
它基本上是拍摄一幅图像并重新调整大小以创建缩略图。它工作得很好。我现在想做的是在右下角添加水印。我已经看到用于此的imagecopymerge
函数。。。但是,这似乎不允许我提供重新采样的图像作为源
如何获取已修改的图像并添加水印/
我曾想过将图像保存到/tmp,然后在添加水印后取消链接(),但这看起来有点乱…您可以使用
$crappedthumb
作为imagecopymerge
的第一个参数。您不必先保存图像