最近很多人使用php的GD庫生成圖片,但是有些人不知道加緩存,導致服務(wù)器壓力很大,所以今天介紹關(guān)于php中GD庫生成圖片并且加入緩存

文章插圖
生成圖片代碼:
<?php$width = 300;$height = 300; $im = imagecreatetruecolor($width,$height);$white = imagecolorallocate($im,255,255,255);$blue = imagecolorallocate($im,0,0,64); imagefill($im,0,0,$blue);imageline($im,0,0,$width,$height,$white);imagestring($im,4,80,150,"Shrimpking Study PHP",$white); //中文會出現(xiàn)亂碼,目前還沒有學習會header("Content-type:image/png");imagepng($im);imagedestroy($im);?>新增瀏覽器頭部緩存,即加入以下代碼:
//開啟緩存session_start(); header("Cache-Control: private, max-age=10800, pre-check=10800");header("Pragma: private");header("Expires: " . date(DATE_RFC822,strtotime(" 2 day"))); 完整的:
<?php$width = 300;$height = 300; $im = imagecreatetruecolor($width,$height);$white = imagecolorallocate($im,255,255,255);$blue = imagecolorallocate($im,0,0,64); imagefill($im,0,0,$blue);imageline($im,0,0,$width,$height,$white);imagestring($im,4,80,150,"Shrimpking Study PHP",$white); //中文會出現(xiàn)亂碼,目前還沒有學習會header("Content-type:image/png");imagepng($im);imagedestroy($im);//開啟緩存session_start(); header("Cache-Control: private, max-age=10800, pre-check=10800");header("Pragma: private");header("Expires: " . date(DATE_RFC822,strtotime(" 2 day")));?>
以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問題,請您及時就醫(yī)或請專業(yè)人士給予相關(guān)指導!
「愛刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對您有所幫助:- 織夢輸入標題后利用百度分詞接口自動生成TAG標簽和關(guān)鍵字
- linux配置php運行環(huán)境 PHP7在Linux下開啟配置使用MongoDB
- PHP類構(gòu)造函數(shù)__construct理解(php的構(gòu)造函數(shù)是)
- PHP版批量查詢百度關(guān)鍵詞排名源碼
- 微信域名攔截狀態(tài)檢測PHP接口版本
- 怎么樣延長蘋果手機電池使用壽命 延長手機電池使用壽命,蘋果和安卓通用技巧分享
- 樟腦丸小袋子要不要撕開使用
- 怎么查詢老賴黑名單 老賴黑名單查詢網(wǎng)站如何使用
- 使用充氣娃娃有什么危害嗎 充氣娃娃怎么樣 使用該注意些什么
- 網(wǎng)約車出行 如何使用網(wǎng)約車出行?
