最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP 圖片水印類(lèi)代碼

 更新時(shí)間:2012年08月27日 22:44:27   作者:  
這個(gè)類(lèi)功能很強(qiáng)大,細(xì)節(jié)很棒!希望大家喜歡,并積極指點(diǎn)
支持文字水印、圖片水印
支持水印的位置隨機(jī)或固定(九宮格)
水印透明度設(shè)置(圖片水印和文字水印都支持)
文字水印的字體、顏色、大小設(shè)置
圖片水印的背景透明
復(fù)制代碼 代碼如下:

<?php
/**
* 加水印類(lèi),支持文字圖片水印的透明度設(shè)置、水印圖片背景透明。
* 日期:2011-09-27
* 作者:www.fzitv.net
* 使用:
* $obj = new WaterMask($imgFileName); //實(shí)例化對(duì)象
* $obj->$waterType = 1; //類(lèi)型:0為文字水印、1為圖片水印
* $obj->$transparent = 45; //水印透明度
* $obj->$waterStr = 'www.fzitv.net'; //水印文字
* $obj->$fontSize = 16; //文字字體大小
* $obj->$fontColor = array(255,0255); //水印文字顏色(RGB)
* $obj->$fontFile = = 'AHGBold.ttf'; //字體文件
* $obj->output(); //輸出水印圖片文件覆蓋到輸入的圖片文件
*/
class WaterMask{
public $waterType = 1; //水印類(lèi)型:0為文字水印、1為圖片水印
public $pos = 0; //水印位置
public $transparent = 45; //水印透明度

public $waterStr = 'www.fzitv.net'; //水印文字
public $fontSize = 16; //文字字體大小
public $fontColor = array(255,0,255); //水印文字顏色(RGB)
public $fontFile = 'AHGBold.ttf'; //字體文件

public $waterImg = 'logo.png'; //水印圖片

private $srcImg = ''; //需要添加水印的圖片
private $im = ''; //圖片句柄
private $water_im = ''; //水印圖片句柄
private $srcImg_info = ''; //圖片信息
private $waterImg_info = ''; //水印圖片信息
private $str_w = ''; //水印文字寬度
private $str_h = ''; //水印文字高度
private $x = ''; //水印X坐標(biāo)
private $y = ''; //水印y坐標(biāo)

function __construct($img) { //析構(gòu)函數(shù)
$this->srcImg = file_exists($img) ? $img : die('"'.$img.'" 源文件不存在!');
}
private function imginfo() { //獲取需要添加水印的圖片的信息,并載入圖片。
$this->srcImg_info = getimagesize($this->srcImg);
switch ($this->srcImg_info[2]) {
case 3:
$this->im = imagecreatefrompng($this->srcImg);
break 1;
case 2:
$this->im = imagecreatefromjpeg($this->srcImg);
break 1;
case 1:
$this->im = imagecreatefromgif($this->srcImg);
break 1;
default:
die('原圖片('.$this->srcImg.')格式不對(duì),只支持PNG、JPEG、GIF。');
}
}
private function waterimginfo() { //獲取水印圖片的信息,并載入圖片。
$this->waterImg_info = getimagesize($this->waterImg);
switch ($this->waterImg_info[2]) {
case 3:
$this->water_im = imagecreatefrompng($this->waterImg);
break 1;
case 2:
$this->water_im = imagecreatefromjpeg($this->waterImg);
break 1;
case 1:
$this->water_im = imagecreatefromgif($this->waterImg);
break 1;
default:
die('水印圖片('.$this->srcImg.')格式不對(duì),只支持PNG、JPEG、GIF。');
}
}
private function waterpos() { //水印位置算法
switch ($this->pos) {
case 0: //隨機(jī)位置
$this->x = rand(0,$this->srcImg_info[0]-$this->waterImg_info[0]);
$this->y = rand(0,$this->srcImg_info[1]-$this->waterImg_info[1]);
break 1;
case 1: //上左
$this->x = 0;
$this->y = 0;
break 1;
case 2: //上中
$this->x = ($this->srcImg_info[0]-$this->waterImg_info[0])/2;
$this->y = 0;
break 1;
case 3: //上右
$this->x = $this->srcImg_info[0]-$this->waterImg_info[0];
$this->y = 0;
break 1;
case 4: //中左
$this->x = 0;
$this->y = ($this->srcImg_info[1]-$this->waterImg_info[1])/2;
break 1;
case 5: //中中
$this->x = ($this->srcImg_info[0]-$this->waterImg_info[0])/2;
$this->y = ($this->srcImg_info[1]-$this->waterImg_info[1])/2;
break 1;
case 6: //中右
$this->x = $this->srcImg_info[0]-$this->waterImg_info[0];
$this->y = ($this->srcImg_info[1]-$this->waterImg_info[1])/2;
break 1;
case 7: //下左
$this->x = 0;
$this->y = $this->srcImg_info[1]-$this->waterImg_info[1];
break 1;
case 8: //下中
$this->x = ($this->srcImg_info[0]-$this->waterImg_info[0])/2;
$this->y = $this->srcImg_info[1]-$this->waterImg_info[1];
break 1;
default: //下右
$this->x = $this->srcImg_info[0]-$this->waterImg_info[0];
$this->y = $this->srcImg_info[1]-$this->waterImg_info[1];
break 1;
}
}
private function waterimg() {
if ($this->srcImg_info[0] <= $this->waterImg_info[0] || $this->srcImg_info[1] <= $this->waterImg_info[1]){
die('水印比原圖大!');
}
$this->waterpos();
$cut = imagecreatetruecolor($this->waterImg_info[0],$this->waterImg_info[1]);
imagecopy($cut,$this->im,0,0,$this->x,$this->y,$this->waterImg_info[0],$this->waterImg_info[1]);
$pct = $this->transparent;
imagecopy($cut,$this->water_im,0,0,0,0,$this->waterImg_info[0],$this->waterImg_info[1]);
imagecopymerge($this->im,$cut,$this->x,$this->y,0,0,$this->waterImg_info[0],$this->waterImg_info[1],$pct);
}
private function waterstr() {
$rect = imagettfbbox($this->fontSize,0,$this->fontFile,$this->waterStr);
$w = abs($rect[2]-$rect[6]);
$h = abs($rect[3]-$rect[7]);
$fontHeight = $this->fontSize;
$this->water_im = imagecreatetruecolor($w, $h);
imagealphablending($this->water_im,false);
imagesavealpha($this->water_im,true);
$white_alpha = imagecolorallocatealpha($this->water_im,255,255,255,127);
imagefill($this->water_im,0,0,$white_alpha);
$color = imagecolorallocate($this->water_im,$this->fontColor[0],$this->fontColor[1],$this->fontColor[2]);
imagettftext($this->water_im,$this->fontSize,0,0,$this->fontSize,$color,$this->fontFile,$this->waterStr);
$this->waterImg_info = array(0=>$w,1=>$h);
$this->waterimg();
}
function output() {
$this->imginfo();
if ($this->waterType == 0) {
$this->waterstr();
}else {
$this->waterimginfo();
$this->waterimg();
}
switch ($this->srcImg_info[2]) {
case 3:
imagepng($this->im,$this->srcImg);
break 1;
case 2:
imagejpeg($this->im,$this->srcImg);
break 1;
case 1:
imagegif($this->im,$this->srcImg);
break 1;
default:
die('添加水印失??!');
break;
}
imagedestroy($this->im);
imagedestroy($this->water_im);
}
}
?>

相關(guān)文章

  • PHP中的表達(dá)式簡(jiǎn)述

    PHP中的表達(dá)式簡(jiǎn)述

    表達(dá)式是 PHP 最重要的基石。在 PHP 中,幾乎所寫(xiě)的任何東西都是一個(gè)表達(dá)式。簡(jiǎn)單但卻最精確的定義一個(gè)表達(dá)式的方式就是“任何有值的東西”。這篇文章主要介紹了PHP中的表達(dá)式簡(jiǎn)述的相關(guān)資料,需要的朋友可以參考下
    2016-05-05
  • laravel 根據(jù)不同組織加載不同視圖的實(shí)現(xiàn)

    laravel 根據(jù)不同組織加載不同視圖的實(shí)現(xiàn)

    今天小編就為大家分享一篇laravel 根據(jù)不同組織加載不同視圖的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-10-10
  • Zend Framework教程之Zend_Helpers動(dòng)作助手ViewRenderer用法詳解

    Zend Framework教程之Zend_Helpers動(dòng)作助手ViewRenderer用法詳解

    這篇文章主要介紹了Zend Framework教程之Zend_Helpers動(dòng)作助手ViewRenderer用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Zend_Helpers動(dòng)作助手ViewRenderer的功能、使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2016-07-07
  • Laravel (Lumen) 解決JWT-Auth刷新token的問(wèn)題

    Laravel (Lumen) 解決JWT-Auth刷新token的問(wèn)題

    今天小編就為大家分享一篇Laravel (Lumen) 解決JWT-Auth刷新token的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-10-10
  • php微信開(kāi)發(fā)之谷歌測(cè)距

    php微信開(kāi)發(fā)之谷歌測(cè)距

    這篇文章主要為大家詳細(xì)介紹了php微信開(kāi)發(fā)之谷歌測(cè)距的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • 簡(jiǎn)單的PHP留言本實(shí)例代碼

    簡(jiǎn)單的PHP留言本實(shí)例代碼

    對(duì)于學(xué)習(xí)php的朋友,開(kāi)始做個(gè)留言板對(duì)于php+mysql的操作有個(gè)簡(jiǎn)單的過(guò)程。學(xué)會(huì)了這個(gè)基本上php開(kāi)始入門(mén)了。
    2010-05-05
  • Laravel學(xué)習(xí)教程之model validation的使用示例

    Laravel學(xué)習(xí)教程之model validation的使用示例

    這篇文章主要給大家介紹了關(guān)于Laravel學(xué)習(xí)教程之model validation使用的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。
    2017-10-10
  • Thinkphp5.0 框架視圖view的比較標(biāo)簽用法分析

    Thinkphp5.0 框架視圖view的比較標(biāo)簽用法分析

    這篇文章主要介紹了Thinkphp5.0 框架視圖view的比較標(biāo)簽用法,結(jié)合實(shí)例形式分析了thinkPHP5框架eq、equal、neq、notequal、egt及switch、range、between等標(biāo)簽相關(guān)用法,需要的朋友可以參考下
    2019-10-10
  • 使用php記錄用戶通過(guò)搜索引擎進(jìn)網(wǎng)站的關(guān)鍵詞

    使用php記錄用戶通過(guò)搜索引擎進(jìn)網(wǎng)站的關(guān)鍵詞

    為了方便SEO,我們需要記錄用戶通過(guò)常見(jiàn)的搜索引擎搜索關(guān)鍵詞,下面是進(jìn)入你網(wǎng)站的情況的相關(guān)實(shí)現(xiàn)代碼,更多的,大家自己拓展咯
    2014-02-02

最新評(píng)論

西乡县| 华坪县| 华蓥市| 乌兰浩特市| 宁德市| 克东县| 宁德市| 陇川县| 绵竹市| 睢宁县| 弥勒县| 和林格尔县| 榆树市| 商河县| 淮阳县| 康乐县| 江阴市| 南召县| 万宁市| 宾阳县| 民丰县| 措勤县| 香港 | 彰化县| 蓬安县| 德保县| 保靖县| 珠海市| 中阳县| 辛集市| 策勒县| 海阳市| 望江县| 镇宁| 乐都县| 邮箱| 曲水县| 永川市| 中卫市| 南充市| 霸州市|