does not want to write out the image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gphp
Forum Commoner
Posts: 29
Joined: Sun Feb 17, 2008 1:40 pm

does not want to write out the image

Post 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);
?>
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: does not want to write out the image

Post by Kieran Huggins »

do a phpinfo() and see if the gd2 library is installed.. that's all I got ;-)
gphp
Forum Commoner
Posts: 29
Joined: Sun Feb 17, 2008 1:40 pm

Re: does not want to write out the image

Post 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);
Post Reply