|
发表于 2014-6-5 13:23:10
|
显示全部楼层
//添加水印--文字
function water_name($pic,$text,$pos=0){
$dst_path = './'.$pic;
$fontSize = 10;
$pos = $pos==0?rand(1,9)pos;
//创建图片的实例
$dst = imagecreatefromstring(file_get_contents($dst_path));
//打上文字
$font = './uploads/fangzheng.ttf';//字体
$black = imagecolorallocate($dst, 0x00, 0x00, 0x00);//字体颜色
$text_arr= $this->text_pos($text,$pos,$font,$fontSize,$pic);
imagefttext($dst,$fontSize, 0, $text_arr[0],$text_arr[1], $black, $font,$text);
//输出图片
list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
switch ($dst_type) {
case 1://GIF
header('Content-Type: image/gif');
imagegif($dst,$dst_path);
break;
case 2://JPG
header('Content-Type: image/jpeg');
imagejpeg($dst,$dst_path);
break;
case 3://PNG
header('Content-Type: image/png');
imagepng($dst,$dst_path);
break;
default:
break;
}
imagedestroy($dst);//销毁图片
} |
|