Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up [SOLVED -- Check for details] PNG not staying transparent after using GD

    Original is transparent, after going through gd it adds white instead of being transparent, if I use imagecreatefromgif instead of png it is transparent BUT the text looks very bad, even when using websafe colors.
    Last edited by Acecool; 09-19-2003 at 08:47 PM.

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Showing the code could help

  • #3
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    $image 
    "./myphpbb.png"
    $im imagecreatefrompng($image); 

    $tc  ImageColorAllocate ($im0X000X360X59);
    $tctwo  ImageColorAllocate ($im0X000X410X93);

    $version '2'.$board_config['version']; 
    $sitename $board_config['sitename']; 
    $total_users get_db_stat('usercount'); 
    $total_posts get_db_stat('postcount'); 
    $total_topics get_db_stat('topiccount'); 
    $newest_userdata get_db_stat('newestuser'); 
    $newest_user $newest_userdata['username']; 

    imageTTFText($im,9,0,7,14,$tctwo,"../addons/fonts/04b_25__.ttf","Live statistics from: $sitename / Acecoolco.com Forum");

    // Row 1
    ImageTTFText($im,7,0,7,24,$tc,"verdana","phpBB Version:");
    ImageTTFText($im,8,0,100,24,$tctwo,"arial","$version");

    ImageTTFText($im,7,0,159,24,$tc,"verdana","Topics:");
    ImageTTFText($im,8,0,209,24,$tctwo,"arial","$total_topics");

    // Its an image, a png
    header("Content-Type: image/PNG");

    Imagepng($im,'',100);
    ImageDestroy ($im);
    ?>

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    gd reads pngs with transparency correctly since version 2.0.12 ( I presume you have that or greater as you're using the compression parameter in the imagepng calls which only works in 2.0.12 and up) though this doesn't mean it also saves the output image with that colour as transparent.

    You'll need ImageColorTransparent and ImageAlphaBlending and some testing time -

    Most notes I've read only indicate people succeeding with single colour indexed transparency from an overlay onto a non transparent background. Not read much about anyone getting far with alpha channel transparencies and GD yet.

    Also note: All the old builds of GD could only use true black as the transparent colour on gifs - am not sure whether that protocol is still true with pngs.

    let us know how you get on and, if successful, what calls you used to get it working please.

    Edit:
    PS - if you do manage to get a colour index to output as transparent you should consider saving your createfrom image as a .gd or .gd2 file format and using imagecreatefromgd or imagecreatefromgd2 - this will both speed up your scripts (due to gd not having to convert to .gd format) and in the uncompressed (.gd) format will let you know how many bytes gd has to play with every time you call that image
    Last edited by Ökii; 09-18-2003 at 12:42 AM.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #5
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    GD Support enabled
    GD Version bundled (2.0.15 compatible)
    FreeType Support enabled
    FreeType Linkage with freetype
    GIF Read Support enabled
    JPG Support enabled
    PNG Support enabled
    WBMP Support enabled
    XBM Support enabled

    ##
    Ill try some stuff
    Thanks.
    Ill let everyone know what I come up with


    ###

    Erm :-/

    $image = "./myphpbb.png";
    $im = imagecreatefrompng($image);
    imagealphablending($im, TRUE);

    $tc = ImageColorAllocate ($im, 0X00, 0X36, 0X59);
    $tctwo = ImageColorAllocate ($im, 0X00, 0X41, 0X93);

    $transparent = ImageColorAllocate ($im, 0xFF, 0xFF, 0xFF);
    imagecolortransparent ($im, $transparent);

    Still not.. I tried with tctwo (the top text, stats thing...)

    No luck, tried experimenting and all :-(

    ###

    $image = "./myphpbb.gif";
    $im = imagecreatefromgif($image);
    imagealphablending($im, TRUE);

    // $tc = ImageColorAllocate ($im, 0X00, 0X36, 0X59);
    // $tctwo = ImageColorAllocate ($im, 0X00, 0X41, 0X93);

    // $transparent = ImageColorAllocate ($im, 0xFF, 0xFF, 0xFF);
    // imagecolortransparent ($im, $transparent);

    Using this makes the image transparent, BUT the text looks bad, its a light gray if I uncomment tc and tctwo
    if I try using web safe colors it wont work either
    Last edited by Acecool; 09-18-2003 at 01:21 AM.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As noted, I've not yet read of anyone having success outputting transparency (either alpha or indexed) in a png with GD - only current successes seem to be doing overlays and then outputting non transparent.

    If Thomas Boutell and developer friends only betad png transparency reading in .0.12 I'd surmise we might have to wait a few more builds until usable output support is available - not that IE can view alpha transparency in png yet.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #7
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm ok..

    any idea about it shows right now?
    Right now its transparent gif... but the text will NOT show correctly

  • #8
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Any ideas?

    If I // comment out the $tc and $tctwo the text shows up blackish, if I uncomment they show up greyish...

    Any ideas in getting the colors to work correctly with imagecreatefromgif?

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    gif (the nasty graphics interchange file format) is restricted to 256 colours no matter what you do - if the background image already uses 256 colours then you cannot add additional colours to it.
    This means that anti-aliased text is impossible on backgrounds with more than about 5 colours.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #10
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Could I use the same color as from the background?

  • #11
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    WEEEEE

    Got it to work with a GIF



    Ok, do this, make a gif image, with transparency, use color allocate, now find somewhere on your image and put 1 pixel of each color somewhere in the image (I put on bottom border) and bingo, works perfectly


  •  

    Posting Permissions

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