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

首頁 > 語言 > PHP > 正文

php使用GD庫實現文字圖片水印及縮略圖教程

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

縮略圖可以通過gd庫來實現,下面我們一起來看一個簡單的php使用GD庫實現文字圖片水印及縮略圖例子,希望此例子能夠為大家帶來有效的幫助.

我們要使用gd庫就必須先打開gd庫,具體如下.

Windows下開啟PHP的GD庫支持.

找到php.ini,打開內容,找到:

;extension=php_gd2.dll

把最前面的分號“;”去掉,再保存即可,如果本來就沒有分號,那就是已經開啟了.

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

  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.  

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凤城市| 青河县| 莱州市| 西城区| 疏勒县| 开封县| 阿克苏市| 虞城县| 高平市| 阿瓦提县| 信宜市| 桃园县| 锡林郭勒盟| 浠水县| 石屏县| 连山| 延庆县| 乌海市| 永康市| 岫岩| 宜川县| 蓝山县| 威海市| 汪清县| 尖扎县| 南川市| 文化| 海宁市| 岐山县| 阜宁县| 中山市| 博湖县| 江孜县| 阳高县| 桦川县| 合作市| 来凤县| 昂仁县| 克拉玛依市| 邛崃市| 吉首市|