开发者

Why php imagefill always black?

This is driving me mad. I would really appreciate i开发者_运维技巧f 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


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.

  1. Ask your hosting service to upgrade GD to latest stable version.

or

  1. Use imagecreate() function to create image identifier instead imagecreatetruecolor().


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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜