PHP gd - 水印 - 如何保存图片?
PHP gd - watermark - how save image?
我在服务器上有图像。我想在图像上制作水印(文本)并将此图像另存为其他名称的新图像。我的函数是:
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。我该怎么做?
来自 imagejpeg()
上的 docs:
filename
The path to save the file to. If not set or NULL, the raw image stream
will be outputted directly.
所以:
imagejpeg ($imageProperties, 'some/path.jpg');
我在服务器上有图像。我想在图像上制作水印(文本)并将此图像另存为其他名称的新图像。我的函数是:
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。我该怎么做?
来自 imagejpeg()
上的 docs:
filename
The path to save the file to. If not set or NULL, the raw image stream will be outputted directly.
所以:
imagejpeg ($imageProperties, 'some/path.jpg');