php圖片加水印原理(超簡單的實例代碼)
更新時間:2013年01月18日 14:59:07 作者:
我看到網(wǎng)上有好多關(guān)于圖片加水印的類,寫的很好 ,我這里只是把相應(yīng)的原理寫下,具體需求,根據(jù)自己的情況來修改,很簡單的,寫的不好,高手見諒
文字水印:
$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); //畫一矩形并填充
// 把字符串寫在圖像左上角
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); //畫一矩形并填充
// 把字符串寫在圖像左上角
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
您可能感興趣的文章:
相關(guān)文章
WordPres對前端頁面調(diào)試時的兩個PHP函數(shù)使用小技巧
這篇文章主要介紹了WordPres對前端頁面調(diào)試時的兩個PHP函數(shù)使用小技巧,分別是過濾Html內(nèi)嵌JavaScript與禁止瀏覽器緩存的方法,需要的朋友可以參考下2015-12-12使用php語句將數(shù)據(jù)庫*.sql文件導(dǎo)入數(shù)據(jù)庫
這篇文章主要介紹了如何使用php語句將數(shù)據(jù)庫*.sql文件導(dǎo)入數(shù)據(jù)庫,需要的朋友可以參考下2014-05-05PHP 防注入函數(shù)(格式化數(shù)據(jù))
下面的函數(shù)通過格式化數(shù)據(jù)的方法實現(xiàn)數(shù)據(jù)的addslashes,不過也建議大家參考下discuz的防注入函數(shù)。2011-08-08PHP中的閉包function()?use()?{}使用場景和技巧
由于存在函數(shù)內(nèi)部不能訪問全局作用的,所以就需要一種可以引入上一級作用域的語法結(jié)構(gòu),可以通過use使用函數(shù)聲明時所在作用域的變量的值。php的閉包可能不常用,但是在某些場合之下還是可以考慮用php的閉包來實現(xiàn)某些功能的。2022-12-12