Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中(使用GD)在已重新采样的图像上覆盖水印?_Php_Image_Gd_Watermark - Fatal编程技术网

如何在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
的第一个参数。您不必先保存图像