php图像加水印

<?php

//图像加水印
//加载图片

$imgfile ="1.jpg";

//将图片文件读取出来,存入到一个变量中

$str =file_get_contents($imgfile);
// $str = file_get_contents("1.jpg");

//字符串编码gb23->utf-8
//$str =iconv('gb2312','utf-8',$str);
//$str =mb_convert_encoding($str,'utf-8',gb2312);
//$str =nl2br($str);
//echo $str;

//创建图像

$img = imagecreatefromstring($str);
if($img === false){
	die('创建图像失败');
}

//加水印 (在图像上输出字符)

$font ="STCAIYUN.ttf";
if(!file_exists($font)){
	die('字体库文件不存在');
}
$text ="xxx版权所有";
$color =imagecolorallocate($img, 255, 255, 255);
imagettftext($img,30,0,50,50,$color,$font,$text);
// header('content-type:image/png');
imagepng($img,'new-'. $imgfile);
imagedestroy($img);
echo '生成图像文件成功';

猜你喜欢

转载自blog.csdn.net/qq_41912774/article/details/84550189
今日推荐