1. 程式人生 > >php 驗證碼 圖像存在錯誤無法顯示

php 驗證碼 圖像存在錯誤無法顯示

沒有 efi 如果 一個 真彩色 class 機會 輸出 判斷

<?php

$height = 300;
$width = 300;
$im = imagecreatetruecolor($width, $height);
$white = imagecolorallocate ($im, 255, 255, 255);
$blue = imagecolorallocate ($im, 0, 0, 64);
imagefill($im, 0, 0, $blue);
imagestring($im, 10, 100, 120, ‘Hello,PHP‘, $white);
ob_clean(); //如果驗證碼輸出不了,加上這一句就可以輸出了
header (‘Content-type: image/png‘);
imagepng(
$im);imagedestroy($im); ?>

<?php
//無bug的國旗測試
//ob_clean();
header("Content-Type:image/jpeg");
$ing = imagecreatetruecolor(700,410);
//新建一個真彩色圖像,返回值為一個圖像標識符,背景默認為黑色,參數(x_size*y_size)
$red = imagecolorallocate($ing,255,0,0);//定義背景顏色
$yellow = imagecolorallocate($ing,237,231,32);//定義黃色
imagefill($ing,0,0,$red
);//填充顏色,以坐標(0,0)開始起填充 //數組坐標,表示(x1,y1,x2,y2,x3,y3.....x11,y11); $a = array(90,30,108,73,157,73,119,102,135,152,93,123,52,152,66,102,29,74,76,73,90,30); imagefilledpolygon($ing,$a,10,$yellow);//畫一個多邊形:10表示頂點總數,$yellow表示填充色 $a1 = array(229,25,229,43,248,48,229,55,229,74,217,60,198,66,210,50,197,34,218,39,229,25); imagefilledpolygon(
$ing,$a1,10,$yellow); $a2 = array(227,108,227,127,245,134,228,139,227,157,215,143,196,149,208,132,196,117,215,122,227,108); imagefilledpolygon($ing,$a2,10,$yellow); $a3 = array(163,184,163,204,181,211,163,216,163,234,152,220,132,225,144,209,132,193,151,199,163,184); imagefilledpolygon($ing,$a3,10,$yellow); $a4 = array(65,209,65,228,84,235,65,240,65,259,54,245,33,249,46,233,34,217,53,224,68,209); imagefilledpolygon($ing,$a4,10,$yellow); imagejpeg($ing); imagedestroy($ing); ?>

註!關於驗證碼無法顯示,首先判斷GD庫是否開啟;

默認配置下,php輸出是先到輸出緩沖區(output_buffering),只要數據還沒有真正發送到瀏覽器(嚴格來說是tcp buffer),那麽還是有機會清空先前的緩沖區裏面的數據,使用內置的ob_clean函數即可。

php 驗證碼 圖像存在錯誤無法顯示