tags:

views:

107

answers:

4

Hello guys 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

+1  A: 

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?

Pekka
+1  A: 

Based on the imagecreatetruecolor() documentation, your server probably doesn't have the correct version of the GD image library installed.

Jordan Ryan Moore
He is getting a 100x100 image and no warning, so it can hardly be the function missing altogether.
Pekka
How do you know he's not getting a warning?
Jordan Ryan Moore
Correct != any. Perhaps his PHP version is using the system GD instead of the bundled GD?
Charles
@Jordan: Because he is linking to a live PNG example (see above). If imagecreatetruecolor() were missing, he would get a fatal error and no image.
Pekka
For certain versions of PHP, it only raises a warning, not a fatal error.
Jordan Ryan Moore
A: 

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.

FreekOne
A: 

solved. imagefilltoborder works.

4lc