PHP的圖像處理實例小結(jié)【文字水印、圖片水印、壓縮圖像等】
本文實例講述了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起點,水印y起點,水印x終點,水印y終點,不透明度) 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è)計算法總結(jié)》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
欄 目:PHP編程
下一篇:PHP單元測試配置與使用方法詳解
本文標(biāo)題:PHP的圖像處理實例小結(jié)【文字水印、圖片水印、壓縮圖像等】
本文地址:http://mengdiqiu.com.cn/a1/PHPbiancheng/10991.html
您可能感興趣的文章
- 04-02關(guān)于txt數(shù)據(jù)庫php的信息
- 04-02php本站才可以請求數(shù)據(jù) php本地數(shù)據(jù)庫
- 04-02網(wǎng)頁里php操作數(shù)據(jù)庫 php網(wǎng)頁例子
- 04-02php打印請求數(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è)計方案
- 04-02php如何用導(dǎo)入數(shù)據(jù) php用來導(dǎo)入其他文件的語句


閱讀排行
本欄相關(guān)
- 04-02php本站才可以請求數(shù)據(jù) php本地數(shù)據(jù)庫
- 04-02關(guān)于txt數(shù)據(jù)庫php的信息
- 04-02php打印請求數(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è)計方
- 04-02php數(shù)據(jù)庫輸入變量 php里輸出數(shù)據(jù)庫數(shù)
- 04-02php如何用導(dǎo)入數(shù)據(jù) php用來導(dǎo)入其他文
隨機(jī)閱讀
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10C#中split用法實例總結(jié)
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-10delphi制作wav文件的方法
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 04-02jquery與jsp,用jquery
- 01-11ajax實現(xiàn)頁面的局部加載
- 08-05織夢dedecms什么時候用欄目交叉功能?