Log in

View Full Version : Resolved PHP compatibility issue with 64-bit Windows machine on php GD library?



dogshasha
02-03-2009, 04:46 PM
Greetings to all,

I have a problem displaying an image on the Web. My environment is PHP 5.2.8, 64-bit Operating System. Windows Server Standard SP1 and is using php5isapi.dll: ISAPI v4.0.

<?php
//require 'config.php';
$image = imagecreate(200, 110);
$bg = imagecolorallocate($image, 225, 0, 0);
$color = imagecolorallocate($image, 255, 255, 255);
imageline($image,10, 10, 60, 60, $color);
header("Content-type: image/png");
imagepng($image);
?>

config.php is a standard php file in the same directory.
<?php
$myvar1='some value';
?>

The problem is if I require(require_once, include) config.php at the beginning of the script(see the red colored line above), the browser gives me the error "The image “http://www.myserver.com/DrawALine.php” cannot be displayed, because it contains errors.". If I comment this line out or move it to the end of the script, the image shows up.

I understand that header must be sent to browser before anything else, even a space character. I double checked to make sure there is no spaces in the script before header("Content-type: image/png");

When I copied the same code to a 32-bit windows machine. It worked.

As far as I can tell, the only difference between my 2 test machines is one is 32-bit and the other is 64-bit.

Can somebody here shed some light on it?

Any suggestions will be greatly appreciated,

Twey
02-03-2009, 08:13 PM
It's not just that the header must be sent before anything else. PNG is a binary format, and therefore very fragile. If anything other than the image data is output, at any point, it will fail with the error you just described. In Firefox, you can go to View->Page Source to see the output in text form, which may shed some more light on the issue. Since it happens on one machine and not another, I suspect that config.php throws an error on that machine, which PHP outputs, thereby messing up the image. It's also possible, though, that there's just some trailing whitespace in config.php which you didn't copy over.

dogshasha
02-03-2009, 09:10 PM
You are correct. It's the problem with config.php. Although I double checked this file and thought I made sure there is no weird characters in this file, apparently there are weird characters in it. I deleted it and created a new one. Then the problem is solved.

Thank you so much,


It's not just that the header must be sent before anything else. PNG is a binary format, and therefore very fragile. If anything other than the image data is output, at any point, it will fail with the error you just described. In Firefox, you can go to View->Page Source to see the output in text form, which may shed some more light on the issue. Since it happens on one machine and not another, I suspect that config.php throws an error on that machine, which PHP outputs, thereby messing up the image. It's also possible, though, that there's just some trailing whitespace in config.php which you didn't copy over.