PHP的圖像處理實(shí)例小結(jié)【文字水印、圖片水印、壓縮圖像等】
本文實(shí)例講述了PHP的圖像處理。分享給大家供大家參考,具體如下:
1、添加文字水印
//1、打開圖片資源
  $src="./material/sea.jpg";
  $info=getimagesize($src);//獲取圖片信息
  $type=image_type_to_extension($info[2],false);//轉(zhuǎn)化圖片類型
  //var_dump($info);
  $fun="imagecreatefrom{$type}";//拼接成為imagecreatefromjpeg()方法
  $image=$fun($src);//新建GD圖片資源
//操作圖片
  $font="./material/segoepr.ttf";
  $content="@SuperTory";
  $color=imagecolorallocate($image,255,255,255);
  imagettftext($image,10,0,0,$info[1]-5,$color,$font,$content);//圖片上寫文字
//輸出圖片
  header("content-type:".$info['mime']);//$imfo['mine']='image/jpeg'
  $output="image{$type}";//拼接成為imagejpeg()方法
  $output($image);//輸出到頁面
  $output($image,'./material/watermarked.'.$type);//輸出到本地路徑
//銷毀圖片內(nèi)存資源
  imagedestroy($image);
2、壓縮圖像
//打開圖像
$src="./material/logo.png";
$info=getimagesize($src);
$type=image_type_to_extension($info[2],false);
$create="imagecreatefrom".$type;
$image=$create($src);
//壓縮
$tinyImg=imagecreatetruecolor(100,100); //新建壓縮后的圖像資源
//將原圖映射到壓縮后的圖像資源上
imagecopyresampled($tinyImg,$image,0,0,0,0,100,100,$info[0],$info[1]);
header("content-type:".$info['mime']);
$output="image{$type}";
//$output($image);
$output($tinyImg);
//銷毀
imagedestroy($image);
imagedestroy($tinyImg);
3、添加水印圖片
//獲取原圖片
$src="./material/sea.jpg";
$info=getimagesize($src);
$type=image_type_to_extension($info[2],false);
$create="imagecreatefrom".$type;
$image=$create($src);
//獲取水印圖片資源
$markSrc="./material/logo.png";
$markInfo=getimagesize($markSrc);
$markType=image_type_to_extension($markInfo[2],false);
$create="imagecreatefrom".$markType;
$markImage=$create($markSrc);
$tinyImg=imagecreatetruecolor(100,100);
imagecopyresampled($tinyImg,$markImage,0,0,0,0,
  100,100,$markInfo[0],$markInfo[1]);
imagecopymerge($image,$tinyImg,$info[0]-100,$info[1]-100,
  0,0,100,100,100);
//合并圖片:(原圖,水印圖,原圖x位置,原圖y位置,水印x起點(diǎn),水印y起點(diǎn),水印x終點(diǎn),水印y終點(diǎn),不透明度)
header("content-type:".$info['mime']);
$output="image{$type}";
$output($image);
imagedestroy($image);
imagedestroy($markImage);
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《PHP數(shù)組(Array)操作技巧大全》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
欄 目:PHP編程
本文標(biāo)題:PHP的圖像處理實(shí)例小結(jié)【文字水印、圖片水印、壓縮圖像等】
本文地址:http://www.jygsgssxh.com/a1/PHPbiancheng/10991.html
您可能感興趣的文章
- 04-02關(guān)于txt數(shù)據(jù)庫php的信息
 - 04-02php本站才可以請(qǐng)求數(shù)據(jù) php本地?cái)?shù)據(jù)庫
 - 04-02網(wǎng)頁里php操作數(shù)據(jù)庫 php網(wǎng)頁例子
 - 04-02php打印請(qǐng)求數(shù)據(jù) php打印輸出結(jié)果
 - 04-02php數(shù)據(jù)庫地址 phpstudy 數(shù)據(jù)庫
 - 04-02php插入數(shù)據(jù)庫為亂碼 php連接數(shù)據(jù)庫亂碼
 - 04-02php數(shù)據(jù)庫數(shù)據(jù)相加 php數(shù)據(jù)庫添加數(shù)據(jù)語句
 - 04-02php數(shù)據(jù)庫輸入變量 php里輸出數(shù)據(jù)庫數(shù)據(jù)函數(shù)
 - 04-02數(shù)據(jù)權(quán)限架構(gòu)思路php 數(shù)據(jù)權(quán)限設(shè)計(jì)方案
 - 04-02php如何用導(dǎo)入數(shù)據(jù) php用來導(dǎo)入其他文件的語句
 


閱讀排行
- 1C語言 while語句的用法詳解
 - 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹的示例代碼(圣誕
 - 3利用C語言實(shí)現(xiàn)“百馬百擔(dān)”問題方法
 - 4C語言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
 - 5c語言計(jì)算三角形面積代碼
 - 6什么是 WSH(腳本宿主)的詳細(xì)解釋
 - 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
 - 8正則表達(dá)式匹配各種特殊字符
 - 9C語言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
 - 10C語言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
 
本欄相關(guān)
- 04-02php本站才可以請(qǐng)求數(shù)據(jù) php本地?cái)?shù)據(jù)庫
 - 04-02關(guān)于txt數(shù)據(jù)庫php的信息
 - 04-02php打印請(qǐng)求數(shù)據(jù) php打印輸出結(jié)果
 - 04-02網(wǎng)頁里php操作數(shù)據(jù)庫 php網(wǎng)頁例子
 - 04-02php插入數(shù)據(jù)庫為亂碼 php連接數(shù)據(jù)庫亂
 - 04-02php數(shù)據(jù)庫地址 phpstudy 數(shù)據(jù)庫
 - 04-02php數(shù)據(jù)庫數(shù)據(jù)相加 php數(shù)據(jù)庫添加數(shù)據(jù)
 - 04-02數(shù)據(jù)權(quán)限架構(gòu)思路php 數(shù)據(jù)權(quán)限設(shè)計(jì)方
 - 04-02php數(shù)據(jù)庫輸入變量 php里輸出數(shù)據(jù)庫數(shù)
 - 04-02php如何用導(dǎo)入數(shù)據(jù) php用來導(dǎo)入其他文
 
隨機(jī)閱讀
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
 - 01-10C#中split用法實(shí)例總結(jié)
 - 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
 - 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
 - 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
 - 01-10delphi制作wav文件的方法
 - 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
 - 04-02jquery與jsp,用jquery
 - 01-11ajax實(shí)現(xiàn)頁面的局部加載
 - 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
 


