Image php脚本生成的firefox中的图像损坏或截断
我有一个php脚本从png图像生成验证码的问题。ie和chrome一切正常。在firefox浏览器中测试脚本时出现问题 我的代码:Image php脚本生成的firefox中的图像损坏或截断,image,firefox,symfony-1.4,captcha,Image,Firefox,Symfony 1.4,Captcha,我有一个php脚本从png图像生成验证码的问题。ie和chrome一切正常。在firefox浏览器中测试脚本时出现问题 我的代码: function executeGenerateCaptcha() { header('Content-Type: image/jpg'); // number of characters to type define('NB_CARACTERE', 6); $sImage = imagecreatefrompng(dirname(__FILE__
function executeGenerateCaptcha()
{
header('Content-Type: image/jpg');
// number of characters to type
define('NB_CARACTERE', 6);
$sImage = imagecreatefrompng(dirname(__FILE__) . '/../captcha/images/fond.png');
$nCpt = 0;
// possible characters for captcha
$aChars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
// string generation
while ($nCpt < NB_CARACTERE)
{
$sCaractere = $aChars{ mt_rand(0, strlen($aChars) - 1)};
$aCaracteres[$nCpt] = $sCaractere;
$nCpt++;
}
$sCode = null;
$iAbcisse = 0;
$iInclinaison = -20;
// characters generation on image
foreach ($aCaracteres as $sCaractere)
{
$sCode .= $sCaractere;
$color = imagecolorallocate($sImage, mt_rand(0, 253), mt_rand(0, 253), mt_rand(0, 253));
imagettftext($sImage, 40, $iInclinaison, 0 + $iAbcisse, 45, $color, dirname(__FILE__) . '/../captcha/images/arial.ttf', $sCaractere);
$iAbcisse = $iAbcisse + 30;
$iInclinaison = $iInclinaison - 12;
}
unset($sCaractere);
unset($nCpt);
unset($sCaractere);
unset($aCaracteres);
imagepng($sImage);
}
函数executeGenerateCaptcha()
{
标题('Content-Type:image/jpg');
//要键入的字符数
定义('NB_CARACTERE',6);
$sImage=imagecreatefrompng(dirname(_文件)'/../captcha/images/fond.png');
$nCpt=0;
//验证码的可能字符
$aChars='123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
//字符串生成
而($nCpt
解决方案就是添加“flush();”在函数末尾保存生成的图像。解决方案只是添加“flush();”在函数末尾保存生成的图像