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 2 of 2

Thread: HEX 2 Colo-u-r

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Brisbane, Australia
    Posts
    181
    Thanks
    1
    Thanked 0 Times in 0 Posts

    HEX 2 Colo-u-r

    If I have a hexidecimal color:

    EG:
    #FFFFFF
    OR:
    #ACED00

    How do i get this to represent this in alphabetical characters

    EG:
    White
    OR:
    Light Green

    Is there a simple mathemtical way to calculate the HEX and turn it into a string?

    -Bash
    -mR_eGo
    _______________________
    Programming since
    3 years old.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What you have is a string containing a color value in hexadecimal notation. The pair of hex digits stands for (in order) red, green and blue. The range of color value is from 0 (none) to 255 (full). You can transform the string value into hex numbers by using this function out of PEAR::Image_Color:

    PHP Code:
    function _splitColor $color )
        {
            
    $color str_replace('#'''$color);
            
    $c[] = hexdecsubstr$color0) );
            
    $c[] = hexdecsubstr$color2) );
            
    $c[] = hexdecsubstr$color4) );
            return 
    $c;
        } 
    The whole package can be found and browsed at http://cvs.php.net/co.php/pear/Image...lor.php?r=1.11 In this package there's also an array of color names and their corresponding hex values, although the keys are the color names. You'd need to sort this array first by a custom function, and then you could loop through it with a foreach loop and get the closest match for the tested color. Then the key of this match is the color name.
    De gustibus non est disputandum.


  •  

    Posting Permissions

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