Re: Making an interactive RGB color picker

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Mar 3, 2008 at 3:13 PM, Keikonium <Keikonium@xxxxxxxxxxx> wrote:
> This may not be exactly what you think, but I didn't know how else to word
>  the title. I basically need to make a script that will go through every
>  possible color combination and print them to look just like (or similar) to
>  the windows color picker. I need it in the format X-Y-Z. For example:
>
>  255-255-255
>  255-254-254
>  255-253-253
[snip!]

    This is a very Bad Idea[tm], because it's going to generate
16,777,216 lines that the browser needs to receive, parse, and
display.  This is going to be over 2,516,582,400 bytes (yes, 2.5GB!)
of data to be served.  There are several better ways of doing it,
including using an HTML image map that has all of the colors laid-out
by pixel coordinates, reducing the number of colors you want to
display, using Flash, or any number of alternatives.

    In any case, here's the code:
<?php
if($_GET['r'] && $_GET['g'] && $_GET['b']) {
        if(
                !preg_match('/^[0-9]{1,3}$/',$_GET['r'])
                || !preg_match('/^[0-9]{1,3}$/',$_GET['g'])
                || !preg_match('/^[0-9]{1,3}$/',$_GET['b'])
        ) {
                die('Incorrect parameters specified.  Please try again.');
        } else {
                echo "You chose the following:\n";
                echo "<b>R</b>: ".$_GET['r']."<br />\n";
                echo "<b>G</b>: ".$_GET['g']."<br />\n";
                echo "<b>B</b>: ".$_GET['b']."<br />\n";
                echo "<br />\n";
        }
}

$newline = 63;

for($i=255;$i>0;$i--) {
        for($j=255;$j>0;$j--) {
                for($k=255;$k>0;$k--) {
                        echo "<span
style=\"background:rgb(".$i.",".$j.",".$k.");padding:0px;height=5px;width=5px;\">";
                        echo "<a href=\"?r=".$i."&g=".$j."&b=".$k."\"";
                        echo "
style=\"color:rgb(".$i.",".$j.",".$k.");\">X</a></span>";
                        if($newline === 0) {
                                echo "<br />\n";
                                $newline = 63;
                        } else {
                                echo "\n";
                                $newline--;
                        }
                }
        }
}
?>

    It's also available to view here (but the demo is limited to save
my server from Yahoo! Slurps, Google grabs, etc.):
        [Demo]     http://www.pilotpig.net/code-library/colorpicker.php
        [Source]
http://www.pilotpig.net/code-library/source.php?f=colorpicker.php
-- 
</Dan>

Daniel P. Brown
Senior Unix Geek
<? while(1) { $me = $mind--; sleep(86400); } ?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux