$path = 'timg.jpg';
//创建图片的实例
$img = imagecreatefromstring(file_get_contents($path));
//打上文字
$font = './simsun.ttc';//字体路径
$black = imagecolorallocate($img, 0x00, 0x00, 0x00);//字体颜色
imagefttext($img, 100(字体大小), 0(角度),100(文字定位x) , 100(文字定位y), $black, $font, '哈哈哈哈哈');
//输出图片
list($img_w, $img_h, $img_type) = getimagesize($path);
switch ($img_type) {
case 1://GIF
header('Content-Type: image/gif');
imagegif($img);
break;
case 2://JPG
header('Content-Type: image/jpeg');
imagejpeg($img);
break;
case 3://PNG
header('Content-Type: image/png');
imagepng($img);
break;
default:
break;
}
imagedestroy($img);
PHP图片加文字水印
最新推荐文章于 2024-05-31 17:24:06 发布