+ -
当前位置:首页 → 问答吧 → PHP版本问题导致image组件不能正常运行

PHP版本问题导致image组件不能正常运行

时间:2011-09-28

来源:互联网

PHP code
<?php

session_start();

//随机码的个数
$_rnd_code = 4;

//创建随机码
for ($i=0; $i<$_rnd_code; $i++) {
    $_nmsg .= dechex(mt_rand(0, 15));
}

//保存在session
$_SESSION['code'] = $_nmsg;

//长和高
$_width = 75;
$_height = 25;

//创建一张图像
$_img = imagecreatetruecolor($_width, $_height);

//白色
$_white = imagecolorallocate($_img, 255, 255, 255);

//填充
imagefill($_img,0,0,$_white);

$_flag = false;

if ($_flag) {
    //黑色,边框
    $_black = imagecolorallocate($_img, 0, 0, 0);
    imagerectangle($_img, 0, 0, $_width-1, $_height-1, $_black);
}

//随即画出6个线条
for ($i=0; $i<6; $i++) {
    $_rnd_color = imagecolorallocate($_img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
    imageline($_img, mt_rand(0, $_width), mt_rand(0, $_height), mt_rand(0, $_width), mt_rand(0, $_height), $_rnd_color);
}

//随即雪花
for ($i=0; $i<100; $i++) {
    $_rnd_color = imagecolorallocate($_img, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255));
    imagestring($_img, 1, mt_rand(1, $_width), mt_rand(1, $_height), '*', $_rnd_color);
}

//输出验证码
for ($i=0; $i<strlen($_SESSION['code']); $i++) {
    $_rnd_color = imagecolorallocate($_img, mt_rand(0, 100), mt_rand(0, 150), mt_rand(0, 200));
    imagestring($_img, 5, $i*$_width/$_rnd_code+mt_rand(1, 10), mt_rand(1, $_height/2), $_SESSION['code'][$i], $_rnd_color);
}

//输出图像
header('Content-Type: image/png');
imagepng($_img);

//销毁
imagedestroy($_img);

?>


以在代码在PHP 5.2.6版本中运行是正常的.
但是我将此代码放在 PHP 5.3.3 中后就不能正常运行了.. 
请问,我需要修改些什么地方,才能够在5.3.3中运行?

作者: takes2589   发布时间: 2011-09-28

没印象 PHP 新版本有升级改动 图像函数. 你将出错信息打开 看看什么提示

作者: PhpNewnew   发布时间: 2011-09-28

正常运行

作者: MoontoC   发布时间: 2011-09-28

error_reporting(E_ALL)试试?

作者: TottyAndBaty   发布时间: 2011-09-28

php 5.3.6 测试通过

作者: xuzuning   发布时间: 2011-09-28

看下你的5.3版本下的php.ini中GD库扩展有没有打开

作者: ohmygirl   发布时间: 2011-09-28

我有打开GD库扩展啊.. 
这么坑爹啊,请问会不会有其它什么问题导致不能正常运行呢?
因为我是使用的WAMP.. 前者是PHP 5.2.6 运行正常!
后来升级后过WAMP 后PHP也升级到5.3.3了,所以这个坑爹的问题就出来了..

作者: takes2589   发布时间: 2011-09-28

error_reporting(E_ALL);
ini_set("display_errors",1);
把错误信息提示出来

作者: yhkyo   发布时间: 2011-09-28

相关阅读 更多