PHP 圖片加水印的方法
阿新 • • 發佈:2017-10-18
reg ima ext file ase list font hit mst $dst_path = ‘https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=1597468794,3856954595&fm=80&w=179&h=119&img.JPEG‘;
//創建圖片的實例
$dst = imagecreatefromstring(file_get_contents($dst_path));
$name=‘小強君‘;
$phone="13161884078";
//打上文字
$font = ‘./AdobeHeitiStd-Regular.otf‘;//字體
$black = imagecolorallocate($dst, 0x00, 0x00, 0x00);//字體顏色
//參數為 圖片,尺寸,旋轉角度,像素位置,字體顏色,文字字體,水印文字
imagefttext($dst, 13, 0, 110, 119, $black, $font, $name);
//輸出圖片
list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
switch ($dst_type) {
case 1://GIF
header(‘Content-Type: image/gif‘);
imagegif($dst,"./".$phone.".gif");
break;
case 2://JPG
header(‘Content-Type: image/jpeg‘);
imagejpeg($dst,"./".$phone.".jpeg");
break;
case 3://PNG
header(‘Content-Type: image/png‘);
imagepng($dst,"./".$phone.".png");
break;
default:
break;
}
imagedestroy($dst);
PHP 圖片加水印的方法