相关知识点:
加载图片:
imagecreatefromgd--从GD文件或URL新建一图像, imagecreatefromgd2--从GD2文件或URL新建一图像, imagecreatefromgif--由文件或URL创建一个新图像, imagecreatfrompng--由文件或URL创建一个新图像, imagecreatefromstring--从字符串的图像流建一图像,
转化字符创的编码:
字符按要求的字符编码来转换: iconv(string $in_charset,string $out_charset,string $str)--将字符串str从in_charset转换编码到out_charset, 转换字符串的编码: mb_convert_encoding(string $str,string $to_encoding[mixed $from_encoding])--将string类型str的字符串从可选的from_encoding转换到to_encoding
本示例主要知识点:imagecreatefromstring--从字符串的图像流建一图像,file_get_contents--将整个文件读入一个字符串,file_exists检查文件或目录是否存在
示例
$imgfile = "图片名称";
$str = file_get_contents($imgfile)
$img = imagecreatefromstring($str);--创建图像
if($img === false){
die('加载图片失败')
}
header('content-type:image/png');
imagepng($img);--输出图像
imagedestroy($img)--销毁图像
$text = "xxx版权所有";
$color = imagecolorallocate($img,255,255,255);
imagettftext($img,30,0,50,50,$color,$fomt,$text);
imagepng($img,'new-' . $imgfile);
imagedestory($img)--销毁图像
echo '生成文件成功';