php 图像 处理,PHP 处理图像步骤解析
PHP 處理圖像步驟解析
發布時間:2020-05-09 16:25:55
來源:億速云
閱讀:309
作者:Leah
今天小編就為大家帶來一篇PHP中處理圖像的文章。小編覺得挺不錯的,為此分享給大家做個參考。一起跟隨小編過來看看吧。
一.創建圖像
創建圖像的一般流程:
1).設定標頭,告訴瀏覽器你要生成的MIME類型。
2).創建一個圖像區域,以后的操作都將基于此圖像區域。
3).在空白圖像區域繪制填充背景。
4).在背景上繪制圖形輪廓輸入文本。
5).輸出最終圖形。
6).清除所有資源。
7).其他頁面調用圖像。
設定標頭指定MIME輸出類型
header('Content-Type: p_w_picpath/png');
?>
創建一個空白的圖像區域
$im= p_w_picpathcreatetruecolor(200,200);
?>
在空白圖像區域繪制填充背景
$blue= p_w_picpathcolorallocate($im,0,102,255);
p_w_picpathfill($im,0,0,$blue);
?>
在背景上繪制圖形輪廓輸入文本
$white= p_w_picpathcolorallocate($im,255,255,255);
p_w_picpathline($im,0,0,200,200,$white);
p_w_picpathline($im,200,0,0,200,$white);
p_w_picpathstring($im,5,80,20,"Mr.Lee",$white);
?>
輸出最終圖形
p_w_picpathpng($im);
?>
清除所有資源
p_w_picpathdestroy($im);
?>
其他頁面調用創建的圖形
二.簡單小案例
簡單驗證碼
header('Content-type: p_w_picpath/png');
//隨機數
for($Tmpa=0;$Tmpa<4;$Tmpa++){
$nmsg.=dechex(rand(0,15));
}
$im= p_w_picpathcreatetruecolor(75,25);
$blue= p_w_picpathcolorallocate($im,0,102,255);
$white= p_w_picpathcolorallocate($im,255,255,255);
p_w_picpathfill($im,0,0,$blue);
p_w_picpathstring($im,5,20,4,$nmsg,$white);
p_w_picpathpng($im);
p_w_picpathdestroy($im);
?>
加載已有的圖像
header('Content-Type:p_w_picpath/png');
define('__DIR__',dirname(__FILE__).'\\');
$im= p_w_picpathcreatefrompng(__DIR__.'222.png');
$white= p_w_picpathcolorallocate($im,255,255,255);
p_w_picpathstring($im,3,5,5,'http://www.yc60.com',$white);
p_w_picpathpng($im);
p_w_picpathdestroy($im);
?>
加載已有的系統字體
$text= iconv("gbk","utf-8","李炎恢");
$font='C:\WINDOWS\Fonts\SIMHEI.TTF';
p_w_picpathttftext($im,20,0,30,30,$white,$font,$text);
?>
圖像微縮
header('Content-type: p_w_picpath/png');
define('__DIR__',dirname(__FILE__).'\\');
list($width,$height) = getp_w_picpathsize(__DIR__.'222.png');
$new_width=$width*0.7;
$new_height=$height*0.7;
$im2= p_w_picpathcreatetruecolor($new_width,$new_height);
$im= p_w_picpathcreatefrompng(__DIR__.'222.png');
p_w_picpathcopyresampled($im2,$im,0,0,0,0,
$new_width,$new_height,$width,$height);
p_w_picpathpng($im2);
p_w_picpathdestroy($im);
Imagedestroy($im2);
?>
看完上訴內容,你們掌握PHP處理圖像的方法了嗎?如果想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
總結
以上是生活随笔為你收集整理的php 图像 处理,PHP 处理图像步骤解析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 蜜雪冰城加盟费多少啊
- 下一篇: 哈密紫云大酒店详细位置