这是我当前的代码:
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,然后在添加水印后取消链接(),但这似乎有点混乱......