婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > PHP開發的文字水印,縮略圖,圖片水印實現類與用法示例

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

熱門標簽:七魚外呼系統停用嗎 抖音有個地圖標注是什么意思 智能電話機器人排名前十名南京 九江外呼系統 阿里云400電話申請加工單 海南人工外呼系統有效果嗎 地下城堡2圖九地圖標注 西區企業怎么做地圖標注入駐 保定crm外呼系統運營商

本文實例講述了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圖形與圖片操作技巧匯總》、《PHP數組(Array)操作技巧大全》、《PHP數據結構與算法教程》、《php程序設計算法總結》、《PHP數學運算技巧總結》、《php字符串(string)用法總結》及《php常見數據庫操作技巧匯總》

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

您可能感興趣的文章:
  • php gd2 上傳圖片/文字水印/圖片水印/等比例縮略圖/實現代碼
  • php文字水印和php圖片水印實現代碼(二種加水印方法)
  • php給圖片添加文字水印方法匯總
  • php圖片添加文字水印實現代碼
  • php給圖片加文字水印
  • php面向對象與面向過程兩種方法給圖片添加文字水印
  • PHP添加文字水印或圖片水印的水印類完整源代碼與使用示例
  • PHP Imagick完美實現圖片裁切、生成縮略圖、添加水印
  • php下圖片文字混合水印與縮略圖實現代碼
  • php圖片處理:加水印、縮略圖的實現(自定義函數:watermark、thumbnail)

標簽:昭通 甘肅 十堰 韶關 涼山 遼陽 梅河口 九江

巨人網絡通訊聲明:本文標題《PHP開發的文字水印,縮略圖,圖片水印實現類與用法示例》,本文關鍵詞  PHP,開發,的,文字,水印,縮,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《PHP開發的文字水印,縮略圖,圖片水印實現類與用法示例》相關的同類信息!
  • 本頁收集關于PHP開發的文字水印,縮略圖,圖片水印實現類與用法示例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 佳木斯市| 聂拉木县| 砚山县| 贺州市| 永顺县| 麦盖提县| 鲁山县| 高州市| 手游| 太白县| 保靖县| 永胜县| 锡林浩特市| 潮州市| 巴林右旗| 二连浩特市| 舟曲县| 沂源县| 肥城市| 尼勒克县| 丹棱县| 西华县| 厦门市| 湖南省| 香河县| 方城县| 五台县| 军事| 葵青区| 大田县| 澜沧| 将乐县| 铜鼓县| 白城市| 舞钢市| 新丰县| 芒康县| 灌阳县| 安龙县| 来凤县| 塔城市|