Transparency Gd Library (Easy)

Posted on 2006-04-11
Last Modified: 2008-03-10
I have a red image with blue text and am trying to make the red  in the image transparent... it doesnt work.. Any ideas??

  $image       = 'ImageManipulation/TemoraryImages/blue.gif';
    $image       = imagecreatefromgif($image);
    //Make transparent all red in the image
    $MakeTrans   = imageColorAllocate($image, 255,0,0);

Question by:boss234
    LVL 17

    Expert Comment

    I don't know much about images, I know some people here do though, so i'll just do my basic error checking =)
    Are you sure the color that your trying to make transparent is exactly (255,0,0)?
    Joe P

    Author Comment

    Yes, i just made it to test the code.
    LVL 9

    Expert Comment

    The problem is that you create a new red palette entry and make that transparent.
    The original red pixels still remain red. You should find the palette index used for red pixels and make it transparent.
    I'm now looking for the php function to read the palette.
    LVL 9

    Expert Comment

    I've found it: the palette index of the red color can be retieved by the imagecolorexact function.

    Author Comment

    Thanks pallosp - - i get a pallet index of ZERO (0) is this right?

    LVL 9

    Accepted Solution

    If making the 0th element transparent solves your problem, definitely it is right.
    -1 means that the given color doesn't exist, so 0 can be a right index.
    You may check it by a photo editor that is able to display the palette of an image (such as Paint Shop Pro).

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now