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

首頁(yè) > 語(yǔ)言 > PHP > 正文

php給圖片加文字水印與圖片水印代碼

2024-09-04 11:44:23
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這款程序給圖片加文字水印時(shí)是調(diào)用 了C://WINDOWS//Fonts////SIMHEI.TTF字體,給圖片加水印時(shí)就可以自定圖片,實(shí)例代碼如下:

  1. $image->wprint_img();//執(zhí)行圖片水印 
  2. $image->wprint_string();//執(zhí)行文字水印 
  3. class editimage{ 
  4.  private $imagefile;//圖片文件 
  5.  private $smallimg;//水印圖片 
  6.  private $string;//水印文字 
  7.  private $position;//存放位置 
  8.  private $dst_x=600;//原始圖片打水印x坐標(biāo) 
  9.  private $dst_y=0;//原始圖片打水印y坐標(biāo) 
  10.  private $str_x=450; 
  11.  private $str_y=200; 
  12.  private $font="c:windows ontssimhei.ttf";//原始圖片打水印字體路徑 
  13.  private $imgej;// imagecolorallocate后的變量 
  14.   
  15.  function __get($value){ 
  16.   return $this->$value
  17.  } 
  18.  function __set($property,$value){ 
  19.   $this->$property=$value
  20.  } 
  21.  /** 
  22.   * 構(gòu)造函數(shù)初始化 
  23.   * 
  24.   * @param string $imagefile 被上水印的文件 
  25.   * @param string $smallimg 水印文件 
  26.   * @param string $string 水印文字 
  27.   * @param string $position 存放位置 
  28.   * @param int $dst_x  被上水印的圖片x 
  29.   * @param int $dst_y  被上水印的圖片y 
  30.   */ 
  31.  function __construct($imagefile,$smallimg='',$string=''){//,$position='',$dst_x=0,$dst_y=0 
  32.   $this->imagefile=$imagefile
  33.   $this->smallimg=$smallimg
  34.   $this->string=$string
  35.   $this->imgej=$this->imagecreatef($this->imagefile); 
  36.  } 
  37.  
  38.  function get_extname($file){//獲取文件的后綴名 
  39.   if (file_exists($this->imagefile)) { 
  40.    $img=getimagesize($file); 
  41.    switch ($img[2]){ 
  42.     case "1"
  43.      return "gif"
  44.     case "2"
  45.      return "jpg"
  46.     case "3"
  47.      return "png"
  48.    } 
  49.   }else
  50.    return false; 
  51.   }  
  52.  }   
  53.  
  54.   
  55. function getsize($file,$wh){//獲取圖大小. $wh:w獲得寬,h獲得高 
  56.   $image=getimagesize($file); 
  57.   if ($wh) { 
  58.    switch ($wh){ 
  59.     case "w"
  60.      return $image[0]; 
  61.     case "h"
  62.      return $image[1]; 
  63.    } 
  64.   }else
  65.    return false; 
  66.   } 
  67.  } 
  68.  function imagecreatef($file){//創(chuàng)建類(lèi)型 
  69.   if ($this->get_extname($file)) { 
  70.    switch($this->get_extname($file)){ 
  71.     case "gif"
  72.      return imagecreatefromgif($file); 
  73.     case "jpg"
  74.      return imagecreatefromjpeg($file); 
  75.     case "png"
  76.      return imagecreatefrompng($file); 
  77.    } 
  78.   }else
  79.    echo "文件不存在"
  80.   } 
  81.  }  
  82.   
  83.  //水印圖片處理 
  84.  function wprint_img(){ 
  85.   if($this->smallimg){ 
  86.    imagecopy($this->imgej,$this->imagecreatef($this->smallimg),$this->dst_x,$this->dst_y,0,0,$this->getsize($this->smallimg,"w"),$this->getsize($this->smallimg,"h")); 
  87.    }else
  88.    return "水印圖片不存在!"
  89.   } 
  90.  } 
  91.  //水印文字處理 
  92.  function wprint_string(){ 
  93.   return imagettftext($this->imgej,20,0,$this->str_x,$this->str_y,imagecolorallocate($this->imgej,200,200,200),$this->font,iconv("gb2312","utf-8",$this->string)); 
  94.  } 
  95.   
  96.  function choose_imgouttype(){//輸出  
  97.    if($this->position){ 
  98.     $this->get_extname($this->imagefile); 
  99.     switch ($this->get_extname($this->imagefile)){ 
  100.     case "gif"
  101.      return imagegif($this->imgej,$position); 
  102.     case "jpg"
  103.      return imagejpeg($this->imgej,$this->position); 
  104.     case "jpeg"
  105.      return imagejpeg($this->imgej,$this->position); 
  106.     case "png"
  107.      return imagepng($this->imgej,$position); 
  108.     } 
  109.    }else
  110.      
  111.     switch ($this->get_extname($this->imagefile)){ 
  112.     case "gif"
  113.      return imagegif($this->imgej); 
  114.     case "jpg"
  115.      return imagejpeg($this->imgej); 
  116.     case "jpeg"
  117.      return imagejpeg($this->imgej); 
  118.     case "png"
  119.      return imagepng($this->imgej); 
  120.     } 
  121.    } 
  122.    
  123.  } 
  124.  
  125. //使用方法如下: 
  126.  
  127. $image=new editimage("d90.gif","hknmtt.png","我的d90"); 
  128. $image->wprint_img();//執(zhí)行圖片水印 
  129. $image->wprint_string();//執(zhí)行文字水印,開(kāi)源代碼Vevb.com 
  130. $image->choose_imgouttype(); 

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 鄂托克前旗| 沅陵县| 湖北省| 新安县| 江达县| 淮阳县| 桐乡市| 金塔县| 鄢陵县| 富平县| 东台市| 镶黄旗| 依安县| 华安县| 新密市| 金沙县| 绥江县| 康马县| 疏附县| 石景山区| 思茅市| 建瓯市| 红原县| 华安县| 咸宁市| 东城区| 封丘县| 深州市| 湖南省| 英吉沙县| 仙游县| 宜春市| 孝感市| 平远县| 东平县| 濮阳县| 栾城县| 弋阳县| 富蕴县| 会同县| 门头沟区|