PHP图片加文字水印

$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);

猜你喜欢

转载自blog.csdn.net/zhou120189162/article/details/79235654