Page 1 of 1

does not want to write out the image

Posted: Wed Jun 18, 2008 11:13 pm
by gphp
Would anyone know what might fix this problem. It does not want to write the image out on Linux but it has no problem to do it on Windows!?
Thanks.

Code: Select all

<?php
 
function draw_grid(&$img, $x0, $y0, $width, $height, $cols, $rows, $color) {
    //draw outer border
    imagerectangle($img, $x0, $y0, $x0+$width*$cols, $y0+$height*$rows, $color);
    //first draw horizontal
    $x1 = $x0;
    $x2 = $x0 + $cols*$width;
    for ($n=0; $n<ceil($rows/2); $n++) {
        $y1 = $y0 + 2*$n*$height;
        $y2 = $y0 + (2*$n+1)*$height;
        imagerectangle($img, $x1,$y1,$x2,$y2, $color);
    }
    //then draw vertical
    $y1 = $y0;
    $y2 = $y0 + $rows*$height;
    for ($n=0; $n<ceil($cols/2); $n++) {
        $x1 = $x0 + 2*$n*$width;
        $x2 = $x0 + (2*$n+1)*$width;
        imagerectangle($img, $x1,$y1,$x2,$y2, $color);
    }
}
 
//example
$img = imagecreatetruecolor(300, 200);
$red   = imagecolorallocate($img, 255, 0, 0);
draw_grid($img, 0,0,15,20,20,10,$red);
 
header("Content-type: image/png");
header("Content-Disposition: inline; filename=gridX.png");
 
$outfile= "gridX.png";
 
//imagepng($img,'gridX.png');   //$outfile);
imagepng($img);
imagedestroy($img);
?>

Re: does not want to write out the image

Posted: Thu Jun 19, 2008 2:43 am
by Kieran Huggins
do a phpinfo() and see if the gd2 library is installed.. that's all I got ;-)

Re: does not want to write out the image

Posted: Thu Jun 19, 2008 4:43 pm
by gphp
I am running CentOS 5 and there is nothing to do for installation since the lib gd is installed. When looking up the info in gd2 it goes to yum install php-gd. So, I guess there is no gd2 available on CentOS and info.php shows only gd installed, nothing about gd2.
This is what I get when trying to save the file: http://127.0.0.1/devtest/img_X.php

Code: Select all

header("Content-type: image/png");
header("Content-Disposition: inline; filename=gridX.png");
 
imagepng($img,'gridX.png');     // http://127.0.0.1/devtest/img_X.php
//imagepng($img);                           // this generates the image for the screen
imagedestroy($img);