在网上抄了一个php图形的程序,运行显示红叉叉<?php
//header("Content-type:text/html;charset=utf-8");
$graphValues = array( 0, 80, 23, 11, 190, 245, 50, 80, 111, 240, 55 );
// Define .PNG image
header( "Content-type:image/png" );
$imgWidth = 250;
$imgHeight = 250;
$image = imagecreate( $imgWidth, $imgHeight );
$colorWhite = imagecolorallocate( $image, 255, 255, 255 );
$colorGrey = imagecolorallocate( $image, 192, 192, 192 );
$colorBlue = imagecolorallocate( $image, 0, 0, 255 );
imageline( $image, 0, 0, 0, 250, $colorGrey );
imageline( $image, 0, 0, 250, 0, $colorGrey );
imageline( $image, 249, 0, 249, 249, $colorGrey );
imageline( $image, 0, 249, 249, 249, $colorGrey );
for ( $i = 1; $i<count($graphValues)+1; $i )
{
imageline( $image, $i*25, 0, $i*25, 250, $colorGrey );
imageline( $image, 0, $i*25, 250, $i*25, $colorGrey );
}
for ( $i = 0; $i<count($graphValues)+1; $i )
{
imageline( $image, $i*25, ( 250-$graphValues[$i] ), ( $i 1 )*25, ( 250-$graphValues[$i 1] ), $colorBlue );
}
imagepng( $image );
imagedestroy( $image );
?>原来弄的一个验证码程序本来是可以运行的,今天在两台电脑上测试,竟然也都突然不能显示了<?php
if( !isset( $_SESSION ) ) session_start();
Header( "Content-type: image/PNG" );
srand( (double)microtime() * 1000000 );
$im = @imagecreate( 62, 20 );
$white = imageColorAllocate( $im, 255, 255, 255 );
$black = imageColorAllocate( $im, 0, 0, 0 );
$gray = imageColorAllocate( $im, 200, 200, 200 );
imagefill( $im, 68, 30, $gray ); $str = 'abcdefghijkmnpqrstuvwxyz0123456789';
$l = strlen($str);
for( $i=1; $i<=4; $i++ )
{
$num = rand( 0, $l-1 );
$authnum .= $str[$num];
} $_SESSION['validate'] = $authnum; //将四位整数验证码绘入图片
imagestring( $im, 5, 10, 3, $authnum, $black );
for( $i=0; $i<300; $i++ ) //加入干扰象素
{
$randcolor = ImageColorallocate( $im, rand( 0, 255 ), rand( 0, 255 ), rand( 0, 255 ) );
imagesetpixel( $im, rand()%70, rand()%30, $randcolor );
}
ImagePNG( $im );
ImageDestroy( $im );
?>运行phpinfo()显示GD库是enable
GD Support  enabled  
GD Version  bundled (2.0.34 compatible)  
FreeType Support  enabled  
FreeType Linkage  with freetype  
FreeType Version  2.1.9  
T1Lib Support  enabled  
GIF Read Support  enabled  
GIF Create Support  enabled  
JPG Support  enabled  
PNG Support  enabled  
WBMP Support  enabled  
XBM Support  enabled  
不知为何会出现这样的现象,是不是运行过第一个程序之后自动修改了设置导致的呢?有没有高手遇到过这种情况,请指点一二,不胜感激!

解决方案 »

  1.   

    就是本机上运行,http://localhost/,以前验证码那个一直可以运行的
      

  2.   

    <?php
        //header("Content-type:text/html;charset=utf-8");
        $graphValues = array( 0, 80, 23, 11, 190, 245, 50, 80, 111, 240, 55 );
        // Define .PNG image
        header( "Content-type:image/png" );
        $imgWidth = 250;
        $imgHeight = 250;
        $image = imagecreate( $imgWidth, $imgHeight );
        $colorWhite = imagecolorallocate( $image, 255, 255, 255 );
        $colorGrey = imagecolorallocate( $image, 192, 192, 192 );
        $colorBlue = imagecolorallocate( $image, 0, 0, 255 );
        imageline( $image, 0, 0, 0, 250, $colorGrey );
        imageline( $image, 0, 0, 250, 0, $colorGrey );
        imageline( $image, 249, 0, 249, 249, $colorGrey );
        imageline( $image, 0, 249, 249, 249, $colorGrey );
        for ( $i = 1; $i<count($graphValues)+1; $i++ )
        {
            imageline( $image, $i*25, 0, $i*25, 250, $colorGrey );
            imageline( $image, 0, $i*25, 250, $i*25, $colorGrey );
        }
        for ( $i = 0; $i<count($graphValues)+1; $i++ )
        {
            imageline( $image, $i*25, ( 250-$graphValues[$i] ), ( $i+1 )*25, ( 250-$graphValues[$i+1] ), $colorBlue );
        }
        imagepng( $image );
        imagedestroy( $image );
    ?>
      

  3.   

    多谢二位,问题找到了,原来是划线的数组索引搞错了,可是我的验证码还是不能运行,郁闷,再研究一下吧。<?php
    //header("Content-type:text/html;charset=utf-8");
    $graphValues = array( 0, 80, 23, 11, 190, 245, 50, 80, 111, 240, 55 );
    // Define .PNG image
    header( "Content-type:image/png" );
    $imgWidth = 250;
    $imgHeight = 250;
    $image = imagecreate( $imgWidth, $imgHeight );
    $colorWhite = imagecolorallocate( $image, 255, 255, 255 );
    $colorGrey = imagecolorallocate( $image, 192, 192, 192 );
    $colorBlue = imagecolorallocate( $image, 0, 0, 255 );
    for( $i=0; $i<count($graphValues); $i++ )
    {
    imageline( $image, $i*25, 0, $i*25, 250, $colorGrey );
    imageline( $image, 0, $i*25, 250, $i*25, $colorGrey );
    }
    for( $i=0; $i<count($graphValues)-1; $i++ )
    {
    imageline( $image, $i*25, ( 250-$graphValues[$i] ), ( $i+1 )*25, ( 250-$graphValues[$i+1] ), $colorBlue );
    }
    imagepng( $image );
    imagedestroy( $image );
    ?>