/    Sign up×
Community /Pin to ProfileBookmark

Why imagefill always black?

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 ([url]http://www.arreglaordenador.com/numberimage2.php[/url]) I see the square in black color instead of red. Do you have any ideas?

[code]
<?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);
?>
[/code]

Thanks

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@hastxDec 14.2009 — You might be viewing a cached image. Delete your browser cache and then revisit the page.
Copy linkTweet thisAlerts:
@thosecars82authorDec 14.2009 — You might be viewing a cached image. Delete your browser cache and then revisit the page.[/QUOTE]

Thanks but I do not think that is the problem. I cleared the cache though, now that you told me. And as I thought I keep seeing the square in black instead of red. I guess you can see it if you click the link as well, can't you?
Copy linkTweet thisAlerts:
@hastxDec 14.2009 — Yes, I see it in black and that makes sense. I dont understand why you see it in red from the localhost.
Copy linkTweet thisAlerts:
@thosecars82authorDec 14.2009 — Yes, I see it in black and that makes sense. I dont understand why you see it in red from the localhost.[/QUOTE]

Hello

Well, I see it in red because I wrote the red color combination, that is to say, (255,0,0) as you can see in the code.

Could you please tell me any suggestion to change the color into white or red or even better, a transparent background?

Thanks
Copy linkTweet thisAlerts:
@hastxDec 14.2009 — edit: I see what you are saying now. it does react different
Copy linkTweet thisAlerts:
@thosecars82authorDec 14.2009 — This would give you a red box:
[code=php]
$im = imagecreatetruecolor(100, 100);

imagefill($im, 0, 0, $red);

header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
[/code]
[/QUOTE]


Thanks for the try. I just tried your code and it keeps showing black.

I have to say, though, that altough I tried like you gave it to me, I would have included some initialization for $red which you did not include.

Any other idea?

Thanks
Copy linkTweet thisAlerts:
@hastxDec 14.2009 — Sorry, I just saw the same thing you saw on my system and it acted differently on localhost vs remote... after refreshing a few times it is displaying red on both now ...I'm trying a few things to reproduce again, ignore the code I gave you I got copy/paste happy.
Copy linkTweet thisAlerts:
@hastxDec 14.2009 — I would try removing all unnecessary white space from the code and try it like this:
[code=php]
$im = imagecreatetruecolor(100, 100);
$red = imagecolorallocate($im, 255, 0, 0);
imagefill($im, 0, 0, $red);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
[/code]


All I can figure is that I made a few changes to format the code and re-saved it and that cleared it up???
Copy linkTweet thisAlerts:
@SheldonDec 14.2009 — Try something like this:

[code=php]

$img = imagecreatetruecolor(100, 100);
// 127 is fully tranparent, 0 would be solid red, 63 would be 50&#37; transparent :)
$background = imagecolorallocatealpha($img, 255, 0, 0, 127);
imagefill($img, 0, 0, $background);
imagealphablending($img, false);
imagesavealpha($img, true);
[/code]


Check this out for making transparent PNG's

http://sheldon.lendrum.co.nz/php-gd-library-css-sprites_416/08/
Copy linkTweet thisAlerts:
@thosecars82authorDec 14.2009 — Try something like this:

[code=php]

$img = imagecreatetruecolor(100, 100);
// 127 is fully tranparent, 0 would be solid red, 63 would be 50&#37; transparent :)
$background = imagecolorallocatealpha($img, 255, 0, 0, 127);
imagefill($img, 0, 0, $background);
imagealphablending($img, false);
imagesavealpha($img, true);
[/code]


Check this out for making transparent PNG's

http://sheldon.lendrum.co.nz/php-gd-library-css-sprites_416/08/[/QUOTE]

The thing is that I just tried this code you told me, well, including three more lines:
<i>
</i>&lt;?php
$img = imagecreatetruecolor(100, 100);
// 127 is fully tranparent, 0 would be solid red, 63 would be 50% transparent :)
$background = imagecolorallocatealpha($img, 255, 0, 0, 110);
imagealphablending($img, false);
imagesavealpha($img, true);
imagefill($img, 1, 1, $background);
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?&gt;

It worked in my local server but not in the remote server(http://www.arreglaordenador.com/numberimage5.php) where you can see that the square is drawed in black instead of red, and that no transparency at all is applied. Do you have any ideas about why this does not work in remote?

Well the settings from the remote server are these:

As for the remote server configuration it is like this:

Configure Command :

'./configure' '--prefix=/usr/local/php5' '--with-mysql=/usr' '--with-gd' '--with-gzip' '--with-zlib' '--with-kerberos' '--enable-ftp' '--enable-gd-native-ttf' '--with-freetype-dir=/usr' '--with-jpeg-dir=/usr' '--with-xpm-dir=/usr' '--with-png-dir=/usr' '--with-imagick' '--enable-bcmath' '--with-xml' '--with-dom' '--with-gettext' '--enable-mbstring' '--with-curl' '--with-imap' '--enable-calendar' '--enable-mhash' '--enable-openssl' '--with-openssl=/usr' '--enable-exif' '--with-mhash=/usr' '--enable-mcrypt' '--with-mcrypt=/usr' '--with-imap-ssl' '--enable-xslt' '--with-dom-xslt=/usr' '--with-xslt-sablot=/usr' '--with-config-file-path=/home/sys/php5' '--with-pgsql=/usr' '--with-pdo-mysql' '--with-pdo-pgqsl' '--with-mysqli' '--with-pear' '--with-iconv' '--with-xsl=/usr' '--enable-fastcgi'
<i>
</i>GD settings:
GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.1.7
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XPM Support enabled
XBM Support enabled


Do you think there is anything wrong with these settings I just wrote? Thanks.
×

Success!

Help @thosecars82 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...