php圖片添加文字浮水印實現代碼,_PHP教程

來源:互聯網
上載者:User

php圖片添加文字浮水印實現代碼,

php類庫給現有的圖片加文字浮水印,代碼不是很完善,歡迎大家多多指教!代碼如下:

img(圖片路徑,浮水印文字,字型路徑,字型大小,字型角度);比如:$tpl->img('abc.jpg','這是浮水印文字','ziti.ttf',30,0)*/class image_fu{private $image;private $img_info;private $img_width;private $img_height;private $img_im;private $img_text;private $img_ttf='';private $img_new;private $img_text_size;private $img_jd;function img($img='',$txt='',$ttf='',$size=12,$jiaodu=0){if(isset($img)&&file_exists($img)){//檢測圖片是否存在$this->image =$img;$this->img_text=$txt;$this->img_text_size=$size;$this->img_jd=$jiaodu;if(file_exists($ttf)){$this->img_ttf=$ttf;}else{exit('字型檔:'.$ttf.'不存在!');}$this->imgyesno();}else{exit('圖片檔案:'.$img.'不存在');}}private function imgyesno(){$this->img_info =getimagesize($this->image);$this->img_width =$this->img_info[0];//圖片寬$this->img_height=$this->img_info[1];//圖片高//檢測圖片類型switch($this->img_info[2]){case 1:$this->img_im = imagecreatefromgif($this->image);break;case 2:$this->img_im = imagecreatefromjpeg($this->image);break;case 3:$this->img_im = imagecreatefrompng($this->image);break;default:exit('圖片格式不支援浮水印');}$this->img_text();}private function img_text(){imagealphablending($this->img_im,true);//設定顏色$color=imagecolorallocate($this->img_im,rand(0,255),rand(0,255),rand(0,255));$txt_height=$this->img_text_size;$txt_jiaodu=$this->img_jd;$ttf_im=imagettfbbox($txt_height,$txt_jiaodu,$this->img_ttf,$this->img_text);$w = $ttf_im[2] - $ttf_im[6];$h = $ttf_im[3] - $ttf_im[7];//$w = $ttf_im[7];//$h = $ttf_im[8];unset($ttf_im);$txt_y =$this->img_height-$h;$txt_x =$this->img_width-$w;//$txt_y =0;//$txt_x =0;$this->img_new=@imagettftext($this->img_im,$txt_height,$txt_jiaodu,$txt_x,$txt_y,$color,$this->img_ttf,$this->img_text);@unlink($this->image);//刪除圖片switch($this->img_info[2]) {//取得背景圖片的格式case 1:imagegif($this->img_im,$this->image);break;case 2:imagejpeg($this->img_im,$this->image);break;case 3:imagepng($this->img_im,$this->image);break;default: exit('浮水印圖片失敗');}}//顯示圖片function img_show(){echo 'image.'" border="0" alt="'.$this->img_text.'" _src="'.$this->image.'"/>';}//釋放記憶體private function img_nothing(){unset($this->img_info);imagedestroy($this->img_im);}}?>

以上就是php圖片添加文字浮水印實現代碼,_PHP教程的內容,更多相關內容請關注topic.alibabacloud.com(www.php.cn)!

http://www.bkjia.com/PHPjc/1110071.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1110071.htmlTechArticlephp圖片添加文字浮水印實現代碼, php類庫給現有的圖片加文字浮水印,代碼不是很完善,歡迎大家多多指教!代碼如下: php/*PHP圖片加文字浮水印...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.