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

首頁 > 語言 > PHP > 正文

PHP開發的文字水印,縮略圖,圖片水印實現類與用法示例

2024-05-05 00:08:22
字體:
來源:轉載
供稿:網友

本文實例講述了PHP開發的文字水印,縮略圖,圖片水印實現類與用法。分享給大家供大家參考,具體如下:

1.實現類ImageToTest.class.php參考代碼

class ImageToTest {  /**   * 圖片的基本信息   */  private $info;  private $image;  public function __construct($src){    $info = getimagesize($src);    $this->info = array(      'width'=> $info[0],      'height'=> $info[1],      'type'=> image_type_to_extension($info[2],false),      'mime'=>$info['mime']    );    $fun = "imagecreatefrom{$this->info['type']}";    $this->image = $fun($src);  }  /**   * 操作圖片 (壓縮)   */  public function thumb($width,$height){    $image_thumb = imagecreatetruecolor($width,$height);    imagecopyresampled($image_thumb,$this->image,0,0,0,0,$width,$height,      $this->info['width'],$this->info['height']);    imagedestroy($this->image);    $this->image = $image_thumb;  }  /**   * 操作圖片(添加文字水印)   */  public function fontMark($content,$font_url,$size,$color,$local,$angle){    $col = imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]);    imagettftext($this->image,$size,$angle,$local['x'],$local['y'],$col,$font_url,$content);  }  /**   * 操作圖片(添加水印圖片)   */  public function imageMark($source,$local,$alpha){    //1.獲取水印圖片的基本信息    $info2 = getimagesize($source);    //2.通過水印的圖片編號來獲取水印的圖片類型    $type2 = image_type_to_extension($info2[2],false);    //3.在內存中創建一個和我們的水印圖像一致的圖像類型    $func2 = "imagecreatefrom{$type2}";    //4.把水印圖片復制到內存中    $water = $func2($source);    //5.合并圖片    imagecopymerge($this->image,$water,$local['x'],$local['y'],0,0,$info2[0],$info2[1],$alpha);    //6.銷毀水印圖片    imagedestroy($water);  }  /**   * 在瀏覽器中輸出圖片   */  public function show(){    header("Content-type:".$this->info['mime']);    $funs = "image{$this->info['type']}";    $funs($this->image);  }  /**   * 把圖片保存到硬盤里   */  public function save($newName){    $funs = "image{$this->info['type']}";    $funs($this->image,'./outPut/'.$newName.'.'.$this->info['type']);  }  /**   * 銷毀圖片 使用析構函數   */  public function __destruct()  {    imagedestroy($this->image);  }}

2.測試參考代碼

require_once('ImageToTest.class.php');/*$src = './image/wbg.jpg';$image = new ImageToTest($src);$image->thumb(700,550);$image->show();*//*$src2 = './image/wbg.jpg';$content = 'SGC';$font_url = './image/YGYcuhei.ttf';$size = 33;$color = array(  0=>2,  1=>222,  2=>222,  3=>60);$local = array(  'x'=>20,  'y'=>100);$angle = 10;$image2 = new ImageToTest($src2);$image2->fontMark($content,$font_url,$size,$color,$local,$angle);$image2->show();$image2->save('hahahah');*/$src3 = './image/wbg.jpg';$source = './image/water.jpg';$local = array(  'x'=>20,  'y'=>100);$font_url = './image/YGYcuhei.ttf';$size = 38;$color = array(  0=>2,  1=>222,  2=>222,  3=>60);$alpha = 60;$angle = 50;$image3 = new ImageToTest($src3);$image3->imageMark($source,$local,$alpha);$image3->thumb(700,550);$image3->fontMark('Hello',$font_url,$size,$color,$local,$angle);$image3->show();$image3->save('WAWAWAWAWA');

希望本文所述對大家PHP程序設計有所幫助。


注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 襄樊市| 沅陵县| 曲松县| 玉田县| 喜德县| 福贡县| 泾阳县| 临江市| 冀州市| 南江县| 邯郸市| 武乡县| 石门县| 弥勒县| 清徐县| 翁牛特旗| 玉山县| 平利县| 阜南县| 太康县| 武穴市| 乃东县| 浙江省| 山阳县| 利辛县| 久治县| 夏邑县| 古蔺县| 沙洋县| 岳池县| 大宁县| 平顶山市| 奉节县| 永宁县| 晴隆县| 鲁甸县| 永兴县| 长武县| 清原| 东乡县| 巴南区|