www.webdeveloper.com
Results 1 to 11 of 11

Thread: Why imagefill always black?

  1. #1
    Join Date
    Apr 2008
    Location
    Arganda, Madrid, Spain
    Posts
    16

    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 (http://www.arreglaordenador.com/numberimage2.php) 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);
    ?>
    Thanks

  2. #2
    Join Date
    May 2003
    Posts
    599
    You might be viewing a cached image. Delete your browser cache and then revisit the page.
    We do precision guesswork

  3. #3
    Join Date
    Apr 2008
    Location
    Arganda, Madrid, Spain
    Posts
    16
    Quote Originally Posted by hastx View Post
    You might be viewing a cached image. Delete your browser cache and then revisit the page.
    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?

  4. #4
    Join Date
    May 2003
    Posts
    599
    Yes, I see it in black and that makes sense. I dont understand why you see it in red from the localhost.
    We do precision guesswork

  5. #5
    Join Date
    Apr 2008
    Location
    Arganda, Madrid, Spain
    Posts
    16
    Quote Originally Posted by hastx View Post
    Yes, I see it in black and that makes sense. I dont understand why you see it in red from the localhost.
    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

  6. #6
    Join Date
    May 2003
    Posts
    599
    edit: I see what you are saying now. it does react different
    Last edited by hastx; 12-14-2009 at 12:19 PM.
    We do precision guesswork

  7. #7
    Join Date
    Apr 2008
    Location
    Arganda, Madrid, Spain
    Posts
    16
    Quote Originally Posted by hastx View Post
    This would give you a red box:
    PHP Code:
    $im imagecreatetruecolor(100100);

    imagefill($im00$red);
     
    header('Content-type: image/png');
    imagepng($im);
    imagedestroy($im); 
    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

  8. #8
    Join Date
    May 2003
    Posts
    599
    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.
    We do precision guesswork

  9. #9
    Join Date
    May 2003
    Posts
    599
    I would try removing all unnecessary white space from the code and try it like this:
    PHP Code:
    $im imagecreatetruecolor(100100);
    $red imagecolorallocate($im25500);
    imagefill($im00$red);
    header('Content-type: image/png');
    imagepng($im);
    imagedestroy($im); 
    All I can figure is that I made a few changes to format the code and re-saved it and that cleared it up???
    We do precision guesswork

  10. #10
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    Try something like this:

    PHP Code:

    $img 
    imagecreatetruecolor(100100);
    //   127 is fully tranparent, 0 would be solid red, 63 would be 50% transparent :)
    $background imagecolorallocatealpha($img25500127);
    imagefill($img00$background);
    imagealphablending($imgfalse);
    imagesavealpha($imgtrue); 
    Check this out for making transparent PNG's
    http://sheldon.lendrum.co.nz/php-gd-...prites_416/08/

  11. #11
    Join Date
    Apr 2008
    Location
    Arganda, Madrid, Spain
    Posts
    16
    Quote Originally Posted by Sheldon View Post
    Try something like this:

    PHP Code:

    $img 
    imagecreatetruecolor(100100);
    //   127 is fully tranparent, 0 would be solid red, 63 would be 50% transparent :)
    $background imagecolorallocatealpha($img25500127);
    imagefill($img00$background);
    imagealphablending($imgfalse);
    imagesavealpha($imgtrue); 
    Check this out for making transparent PNG's
    http://sheldon.lendrum.co.nz/php-gd-...prites_416/08/
    The thing is that I just tried this code you told me, well, including three more lines:
    Code:
    <?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);
    ?>
    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'
    Code:
    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.
    Last edited by thosecars82; 12-14-2009 at 03:52 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles