2010-05-25 85 views
0

这里是我当前的代码:如何在PHP中使用已重新采样的图像覆盖水印(使用GD)?

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目录,然后断开链接()荷兰国际集团一次我添加水印,但是这似乎是一个有点乱......

回答

0

你可以使用$croppedThumb作为imagecopymerge的第一个参数。您不必首先保存图像。