php圖片加水印原理(超簡(jiǎn)單的實(shí)例代碼)
更新時(shí)間:2013年01月18日 14:59:07 作者:
我看到網(wǎng)上有好多關(guān)于圖片加水印的類,寫(xiě)的很好 ,我這里只是把相應(yīng)的原理寫(xiě)下,具體需求,根據(jù)自己的情況來(lái)修改,很簡(jiǎn)單的,寫(xiě)的不好,高手見(jiàn)諒
文字水印:
$w = 80;
$h = 20;
$im = imagecreatetruecolor($w,$h);
$textcolor = imagecolorallocate($im, 123, 12, 255);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $grey); //畫(huà)一矩形并填充
// 把字符串寫(xiě)在圖像左上角
imagestring($im, 3, 2, 3, "Hello world!", $textcolor);
// 輸出圖像
header("Content-type: image/jpeg");
imagejpeg($im);
imagedestroy($im);
圖片水印
$groundImg = "DSC05940.jpeg";
$groundInfo = getimagesize($groundImg);
$ground_w = $groundInfo[0];
//print_r($groundInfo);
$ground_h = $groundInfo[1];
switch($groundInfo[2]){
case 1:
$ground_im = imagecreatefromgif($groundImg);
break;
case 2:
$ground_im = imagecreatefromjpeg($groundImg);
break;
case 3:
$ground_im = imagecreatefrompng($groundImg);
break;
}
$waterImg = "DSC05949.jpeg";
$imgInfo =getimagesize($waterImg);
$water_w = $imgInfo[0];
$water_w = $imgInfo[1];
switch($imgInfo[2]){
case 1:
$water_im = imagecreatefromgif($waterImg);
break;
case 2:
$water_im = imagecreatefromjpeg($waterImg);
break;
case 3:
$water_im = imagecreatefrompng($waterImg);
break;
}
imagecopy($ground_im,$water_im,100,100,0,0,500,500);
header("Content-type: image/jpeg");
imagejpeg($ground_im);
合并圖片php提供了很多函數(shù):例如:imagecopymerge,imagecopyresized
復(fù)制代碼 代碼如下:
$w = 80;
$h = 20;
$im = imagecreatetruecolor($w,$h);
$textcolor = imagecolorallocate($im, 123, 12, 255);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $grey); //畫(huà)一矩形并填充
// 把字符串寫(xiě)在圖像左上角
imagestring($im, 3, 2, 3, "Hello world!", $textcolor);
// 輸出圖像
header("Content-type: image/jpeg");
imagejpeg($im);
imagedestroy($im);
圖片水印
$groundImg = "DSC05940.jpeg";
$groundInfo = getimagesize($groundImg);
$ground_w = $groundInfo[0];
//print_r($groundInfo);
$ground_h = $groundInfo[1];
switch($groundInfo[2]){
case 1:
$ground_im = imagecreatefromgif($groundImg);
break;
case 2:
$ground_im = imagecreatefromjpeg($groundImg);
break;
case 3:
$ground_im = imagecreatefrompng($groundImg);
break;
}
$waterImg = "DSC05949.jpeg";
$imgInfo =getimagesize($waterImg);
$water_w = $imgInfo[0];
$water_w = $imgInfo[1];
switch($imgInfo[2]){
case 1:
$water_im = imagecreatefromgif($waterImg);
break;
case 2:
$water_im = imagecreatefromjpeg($waterImg);
break;
case 3:
$water_im = imagecreatefrompng($waterImg);
break;
}
imagecopy($ground_im,$water_im,100,100,0,0,500,500);
header("Content-type: image/jpeg");
imagejpeg($ground_im);
合并圖片php提供了很多函數(shù):例如:imagecopymerge,imagecopyresized
您可能感興趣的文章:
- 功能強(qiáng)大的PHP圖片處理類(水印、透明度、旋轉(zhuǎn))
- ThinkPHP水印功能實(shí)現(xiàn)修復(fù)PNG透明水印并增加JPEG圖片質(zhì)量可調(diào)整
- php加水印的代碼(支持半透明透明打水印,支持png透明背景)
- PHP 透明水印生成代碼
- php上傳圖片并給圖片打上透明水印的代碼
- php文字水印和php圖片水印實(shí)現(xiàn)代碼(二種加水印方法)
- 用來(lái)給圖片加水印的PHP類
- php給圖片添加文字水印方法匯總
- 超級(jí)好用的一個(gè)php上傳圖片類(隨機(jī)名,縮略圖,加水印)
- php使用imagecopymerge()函數(shù)創(chuàng)建半透明水印
相關(guān)文章
PHP中防止SQL注入攻擊和XSS攻擊的兩個(gè)簡(jiǎn)單方法
所有有打印的語(yǔ)句如echo,print等 在打印前都要使用htmlentities() 進(jìn)行過(guò)濾,這樣可以防止Xss,注意中文要寫(xiě)出htmlentities2010-04-04
php中日期加減法運(yùn)算實(shí)現(xiàn)代碼
通過(guò)對(duì)某個(gè)日期增加或減去幾天,得到另外一個(gè)日期2011-12-12
簡(jiǎn)介PHP的Yii框架中緩存的一些高級(jí)用法
這篇文章主要介紹了PHP的Yii框架中緩存的一些高級(jí)用法,包括頁(yè)面緩存與會(huì)話緩存限制器等內(nèi)容,需要的朋友可以參考下2016-03-03
php將mysql數(shù)據(jù)庫(kù)整庫(kù)導(dǎo)出生成sql文件的具體實(shí)現(xiàn)
下面是php將mysql數(shù)據(jù)庫(kù)整庫(kù)導(dǎo)出生成sql文件的詳細(xì)代碼,希望對(duì)大家在用php編程時(shí)備份數(shù)據(jù)有一定幫助2014-01-01

