您的位置:首页 > 其它

在图片上添加文字水印

2015-11-24 12:49 309 查看
<?php
/**
打开任何一种格式的图片 在图片的中间加上一个文字水印 保存
只是保存下来 并不会输出到浏览器
*/
function imagewater($filename,$string){
//获得图片的属性
list($width,$height,$type) = getimagesize($filename);
//可以处理的照片的类型
$types = array(1=>"gif",2=>"jpeg",3=>"png");
//通过图片类型去组合变量函数
$createfrom = "imagecreatefrom".$types[$type];
//用变量函数去打开图片
$image = $createfrom($filename);
//设定加入文字的位置是在中间
$x = ($width - imagefontwidth(5) * strlen($string)) / 2;
$y = ($height - imagefontwidth(5)) / 2;
//设置文字颜色
$textcolor = imagecolorallocate($image,255,0,0);
//将字符串画在图片上
imagestring($image,5,$x,$y,$string,$textcolor);
//根据图片类型组合变量函数
$output = "image".$types[$type];
//通过变量函数保存到原类型的图片
$output($image,$filename);
//$output($image);
imagedestroy($image);
}

image("mm2.jpg","banbanban");
?>


imagewater
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: