0

这是我当前的代码:

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,然后在添加水印后取消链接(),但这似乎有点混乱......

4

1 回答 1

0

您可以将$croppedThumb其用作 的第一个参数imagecopymerge。您不必先保存图像。

于 2010-05-25T04:33:27.207 回答