1.简单的给图片添加水印
2.可以是远程图片
3.字符串不支持中文,有需要可以自己研究一下
class Image{
/**
*给图片添加水印
*@param $src 图片路径
*@param $str 要添加的字符串
*/
function editimg($src,$str){
//打开图片
$info = getimagesize($src);
$width = $info[0];
$height = $info[1];
$type = image_type_to_extension($info[2],false);
$fun = 'imagecreatefrom'.$type;
$image = $fun($src);
//操作图片 创建一个100*100的真彩色的图片
$im = imagecreatetruecolor($width, $width);
//将原图复制到真彩色图片上
$img = imagecopyresampled($im, $image, 0, 0, 0, 0, $width, $width, $info[0], $info[1]);
$black = imagecolorallocate($im, 0, 0, 0);
//画一个横向字符串
imagestring($im , 5, 10, 10, $str, $black );
//输出图片
header('Content-type:info["mine"]');
$fun = 'image'.$type;
$fun($im);
//释放内存
imagedestroy($im);
}
}
$img = new Image();
$img->editimg('abc.png','test');