PHP生成圖片加水印圖片上加名字自定義文字展示

這裏需要填寫本地的字體路徑,而且WIN系統必須是自帶的字體纔行。我使用的是:simhei.ttf

下載地址是:simhei.ttf

//1.配置圖片路徑  
$src = "imgshuiyin/1.png";  
//2.獲取圖片信息  
$info = getimagesize($src);  
//3.通過編號獲取圖像類型  
$type = image_type_to_extension($info[2],false);  
//4.在內存中創建和圖像類型一樣的圖像  
$fun = "imagecreatefrom".$type;  
//5.圖片複製到內存  
$image = $fun($src);  
  
/*操作圖片*/  
//1.設置字體的路徑  
$font = "imgshuiyin/font/simhei.ttf";  
//2.填寫水印內容  
$content = "huhu905";  
//3.設置字體顏色和透明度  
$color = imagecolorallocatealpha($image, 155, 155, 255, 0);  
//4.寫入文字 (圖片資源,字體大小,旋轉角度,座標x,座標y,顏色,字體文件,內容) 
$a = imagettftext($image, 50, 0, 400, 100, $color, $font, $content);  
//var_dump($a);exit;
/*輸出圖片*/  
//瀏覽器輸出  
header("Content-type:".$info['mime']);  
$fun = "image".$type;  
$fun($image);  
//保存圖片  
$fun($image,'imgshuiyin/bg_res.'.$type);  
/*銷燬圖片*/  
imagedestroy($image);

exit;

https://blog.csdn.net/inite/article/details/80289423

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章