Reputation: 11
This is driving me mad. I would really appreciate if you told me any idea about why I see this square in red color just in my local xampp installation. If I run the code in the remote server (http://www.arreglaordenador.com/numberimage2.php) I see the square in black color instead of red. Do you have any ideas?
<?php
$im = imagecreatetruecolor(100, 100);
// sets background to red
$red = imagecolorallocate($im, 255, 0, 0);
imagefill($im, 0, 0, $red);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
Thanks
Upvotes: 1
Views: 3182
Reputation: 3948
It's because you have used imagecreatetruecolor()
function to create image and your GD version has bugs. imagecreatetruecolor()
won't override by some color function in some GD versions(I don't remember which). You have two solutions.
or
imagecreate()
function to create image identifier instead imagecreatetruecolor()
.Upvotes: 3
Reputation: 10825
This is definitely a GD issue on your server because your code works just fine on both my local WAMP and on my hosting account.
Upvotes: 0
Reputation: 6887
Based on the imagecreatetruecolor()
documentation, your server probably doesn't have the correct version of the GD image library installed.
Upvotes: 1
Reputation: 449385
Can you try allocating a different colour first?
$black = imagecolorallocate($im, 0, 0, 0);
$red = imagecolorallocate($im, 255, 0, 0);
I don't exactly see why, but this looks like a transparency issue to me (i.e. red being selected as a transparent colour for some reason).
Most probably, this is due to different GD versions. Can you compare which one you have locally and which one remotely?
Upvotes: 1