這篇文章主要介紹“php不能生成圖片如何解決”,在日常操作中,相信很多人在php不能生成圖片如何解決問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”php不能生成圖片如何解決”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
10年積累的做網(wǎng)站、成都網(wǎng)站設(shè)計經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有阜陽免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
解決辦法
1、打開gd2庫,通過phpinfo進行查看。清除bom,代碼是頂行開始寫的,所以問題可能出現(xiàn)在代碼上。
2、在header前加上ob_clean()語句,隨后就可以運行了。
注意點
生成圖片時,header('Content-type: image/png');前面不能有輸出?;蛘?,前面加:ob_clean(); 即使用輸出也可以通過這句來清除輸出緩存。
解決實例
//設(shè)置 驗證碼高度寬度\上面字符個數(shù) $img_w = 70; $img_h = 22; $font = 5; $char_len = 5; //數(shù)組合并, range()函數(shù)返回一個范圍數(shù)組 $char = array_merge ( range ( 'a', 'z' ), range ( 'A', 'Z' ), range ( '1', '9' ) ); $rand_keys = array_rand ( $char, $char_len ); //隨機從數(shù)組中取指定個數(shù)的元素,生成鍵值 if ($char_len == 1) { //若只有一個數(shù),則array_rand()返回非數(shù)組類型 $rand_keys = array ($rand_keys ); } shuffle($rand_keys); //可以不用 $code = ''; foreach ( $rand_keys as $k ) { $code .= $char [$k]; } session_start (); $_SESSION ['captcha'] = $code; //添加線、色 //創(chuàng)建新圖像 $img = imagecreatetruecolor ( $img_w, $img_h ); //分配顏色 $bg_color = imagecolorallocate ( $img, 0xcc, 0xcc, 0xcc ); //畫布背景色 imagefill ( $img, 0, 0, $bg_color ); //干擾線 for($i = 0; $i < 300; ++$i) { $color = imagecolorallocate ( $img, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) ); imagesetpixel ( $img, mt_rand ( 0, $img_w ), mt_rand ( 0, $img_h ), $color ); } for($i = 0; $i <= 10; ++ $i) { //設(shè)置直線顏色 $color = imageColorAllocate ( $img, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) ); //在$img圖像上隨機畫一條直線 imageline ( $img, mt_rand ( 0, $img_w ), mt_rand ( 0, $img_h ), mt_rand ( 0, $img_w ), mt_rand ( 0, $img_h ), $color ); //imagesetpixel($img,mt_rand(0,$img_w),mt_rand(0,$img_h),$color); } //加加框 $rect_color = imagecolorallocate ( $img, 0x90, 0x90, 0x90 ); imagerectangle ( $img, 0, 0, $img_w - 1, $img_h - 1, $rect_color ); $str_color = imagecolorallocate ( $img, mt_rand ( 0, 100 ), mt_rand ( 0, 100 ), mt_rand ( 0, 100 ) ); $font_w = imagefontwidth ( $font ); $font_h = imagefontheight ( $font ); $str_len = $font_w * $char_len; imagestring ( $img, $font, ($img_w - $str_len) / 2, ($img_h - $font_h) / 2, $code, $str_color );
到此,關(guān)于“php不能生成圖片如何解決”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
本文標(biāo)題:php不能生成圖片如何解決
轉(zhuǎn)載來于:http://chinadenli.net/article10/gppjdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、網(wǎng)站導(dǎo)航、網(wǎng)站制作、全網(wǎng)營銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)