国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

利用php GD庫 文字圖片水印 縮略圖

2024-09-04 11:44:38
字體:
來源:轉載
供稿:網友

GD庫是php中一個默認的強大的圖片處理庫了,我們可以利用它來對圖片進行一些操作或生成圖片的操作,下面我們來看文字圖片水印縮略圖在php中的實例。

一:添加文字水印 使用方法

  1. require 'image.class.php' 
  2. $src="001.jpg"
  3. $content="hello"
  4. $font_url="my.ttf"
  5. $size=20; 
  6. $image=new Image($src); 
  7. $color=array
  8. 0=>255, 
  9. 1=>255, 
  10. 2=>255, 
  11. 2=>20 
  12. ); 
  13. $local=array
  14. 'x'=>20, 
  15. 'y'=>30 
  16. ); 
  17. $angle=10; 
  18. $image->fontMark($content,$font_url,$size,$color,$local,$angle); 
  19. $image->show(); 

二:圖片縮略圖 使用方法:

  1. require 'image.class.php' 
  2. $src="001.jpg"
  3. $image=new Image($src); 
  4. $image->thumb(300,200); 
  5. $image->show(); 

三:image.class.php

  1. class image{ 
  2. private $info
  3. private $image
  4. public function __contruct($src){ 
  5. $infogetimagesize($src); 
  6. $this->info=array
  7. 'width'=> $info[0], 
  8. 'height'=>$info[1], 
  9. 'type'=>image_type_to_extension($info[2],false), 
  10. 'mime'=>$info['mime'], 
  11.  
  12. ); 
  13. $fun="imagecreatefrom{$this->info['type']}"
  14.  
  15. $this->image= $fun($src); 
  16.  
  17.  
  18. //縮略圖 
  19. public function thumd($width,$height){ 
  20. $image_thumb= imagecreatetruecolor($width,$height); 
  21. imagecopyresampled($image_thumb,$this->image,0,0,0,0,$width,$height,$this->info['width'],$this->info['height']); 
  22. imagedestroy($this->image); 
  23. $this->image=$image_thumb
  24.  
  25. //文字水印 
  26. public function fontMark($content,$font_url,$size,$color,$local,$angle){ 
  27.  
  28. $col=imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]); 
  29. $text=imagettftext($this->image,$size,$angle,$local['x'],$local['y'],$col,$font_url,$content); 
  30. //輸出圖片 
  31. public function show() 
  32. header("Content-type:",$this->info['mime']); 
  33.  
  34. $func="image{$this->info['type']}"
  35. $func($this->image); 
  36.  
  37. public function save($nwename){ 
  38. $func="image{$this->info['type']}"
  39. //從內存中取出圖片顯示 
  40. $func($this->image); 
  41. //保存圖片 
  42. $func($this->image,$nwename.$this->info['type']); 
  43. //Vevb.com 
  44. public function _destruct(){ 
  45.  
  46. imagedestroy($this->image); 
  47.  
  48. }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 上思县| 四平市| 庆元县| 南京市| 元氏县| 秀山| 南城县| 鄂温| 红安县| 新乡市| 石狮市| 海伦市| 武山县| 大方县| 泰安市| 九龙县| 神农架林区| 聊城市| 岑巩县| 中卫市| 历史| 芒康县| 榆中县| 乳山市| 达拉特旗| 九江市| 舒城县| 宝应县| 沛县| 河南省| 渭南市| 铁岭市| 曲松县| 瓦房店市| 城口县| 分宜县| 临颍县| 东平县| 平泉县| 安溪县| 西丰县|