Re: Re: Trying to create a colortable - what am I missing here?

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

 




On Tue, 2009-05-12 at 18:05 +0300, Thodoris wrote:
Still curious about the right script though (if this is possible of
course).

Of course it's possible... but you're probably not going to get the
results you want since you're taking 3 dimensions and trying to push
them into 2. You'll notice most colour pickers have a square for a given
colour, and a bar to pick the colour. The following will produce a
colour picker, but it won't look like what you expect:

<?php

$width = $height = 500;

$im = imagecreatetruecolor( $width, $height );

$root = pow( $width * $height, 1/3 );

$x = $y =  0;
for( $r = 0; $r < $root; $r++ )
{
    $rv = (int)(256 * ($r / $root));

    for( $g = 0; $g < $root; $g++ )
    {
        $gv = (int)(256 * ($g / $root));

        for( $b = 0; $b < $root; $b++ )
        {
            $bv = (int)(256 * ($b / $root));

            $n = imagecolorallocate( $im, $rv, $gv, $bv );
            imagesetpixel( $im, $x, $y, $n );
if( ++$x >= $width )
            {
                $x = 0;
                $y++;
            }
        }
    }
}

header( "Content-Type: image/png" );
imagepng( $im );
imagedestroy( $im );

?>

Cheers,
Rob.

Thanks for pointing to the right direction Rob. I should really consider some reading on image manipulation theory.

My curiosity still beats my reading though.

--
Thodoris


[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