PHP gd - 水印 - 如何保存图像?

时间:2016-01-12 12:56:56

标签: php-gd

我在服务器上有图像。我想在图像上制作水印(文本)并将此图像保存为具有其他名称的新图像。我的职责是:

function watermark($path, $watermark){
    $imageURL = $path;
    list($width,$height) = getimagesize($imageURL);
    $imageProperties = imagecreatetruecolor($width, $height);
    $targetLayer = imagecreatefromjpeg($imageURL);
    imagecopyresampled($imageProperties, $targetLayer, 0, 0, 0, 0, $width,      $height, $width, $height);
    $WaterMarkText = $watermark;
    $watermarkColor = imagecolorallocate($imageProperties, 191,191,191);
    imagestring($imageProperties, 5, 130, 117, $WaterMarkText, $watermarkColor);
    imagejpeg ($imageProperties);
    imagedestroy($targetLayer);
    imagedestroy($imageProperties);
}

其中参数为:

$watermark = $_POST['watermark'];
$path = "/images/$file_name";

当我开始scypt时,带有水印的图像正在创建并显示在屏幕上。我的目标是不显示新图像,而是保存在名称相同的文件夹中:$ file_name_watermark。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

来自imagejpeg()上的docs

  

filename

     

将文件保存到的路径。如果未设置或为NULL,则为原始图像流   将直接输出。

所以:

imagejpeg ($imageProperties, 'some/path.jpg');
相关问题