php圖片加水印原理(超簡(jiǎn)單的實(shí)例代碼)
更新時(shí)間:2013年01月18日 14:59:07 作者:
我看到網(wǎng)上有好多關(guān)于圖片加水印的類(lèi),寫(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圖片處理類(lèi)(水印、透明度、旋轉(zhuǎn))
- ThinkPHP水印功能實(shí)現(xiàn)修復(fù)PNG透明水印并增加JPEG圖片質(zhì)量可調(diào)整
- php加水印的代碼(支持半透明透明打水印,支持png透明背景)
- PHP 透明水印生成代碼
- php上傳圖片并給圖片打上透明水印的代碼
- php文字水印和php圖片水印實(shí)現(xiàn)代碼(二種加水印方法)
- 用來(lái)給圖片加水印的PHP類(lèi)
- php給圖片添加文字水印方法匯總
- 超級(jí)好用的一個(gè)php上傳圖片類(lèi)(隨機(jī)名,縮略圖,加水印)
- php使用imagecopymerge()函數(shù)創(chuàng)建半透明水印
相關(guān)文章
WordPres對(duì)前端頁(yè)面調(diào)試時(shí)的兩個(gè)PHP函數(shù)使用小技巧
這篇文章主要介紹了WordPres對(duì)前端頁(yè)面調(diào)試時(shí)的兩個(gè)PHP函數(shù)使用小技巧,分別是過(guò)濾Html內(nèi)嵌JavaScript與禁止瀏覽器緩存的方法,需要的朋友可以參考下2015-12-12使用php語(yǔ)句將數(shù)據(jù)庫(kù)*.sql文件導(dǎo)入數(shù)據(jù)庫(kù)
這篇文章主要介紹了如何使用php語(yǔ)句將數(shù)據(jù)庫(kù)*.sql文件導(dǎo)入數(shù)據(jù)庫(kù),需要的朋友可以參考下2014-05-05PHP 防注入函數(shù)(格式化數(shù)據(jù))
下面的函數(shù)通過(guò)格式化數(shù)據(jù)的方法實(shí)現(xiàn)數(shù)據(jù)的addslashes,不過(guò)也建議大家參考下discuz的防注入函數(shù)。2011-08-08php實(shí)現(xiàn)的操作excel類(lèi)詳解
這篇文章主要介紹了php實(shí)現(xiàn)的操作excel類(lèi),較為詳細(xì)的分析說(shuō)明了PHP操作excel的具體技巧,包括PHP針對(duì)excel的創(chuàng)建、打開(kāi)、讀取、修改等,需要的朋友可以參考下2016-01-01PHP中的閉包function()?use()?{}使用場(chǎng)景和技巧
由于存在函數(shù)內(nèi)部不能訪問(wèn)全局作用的,所以就需要一種可以引入上一級(jí)作用域的語(yǔ)法結(jié)構(gòu),可以通過(guò)use使用函數(shù)聲明時(shí)所在作用域的變量的值。php的閉包可能不常用,但是在某些場(chǎng)合之下還是可以考慮用php的閉包來(lái)實(shí)現(xiàn)某些功能的。2022-12-12