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

From: Date: Tue, 12 May 2009 15:27:42 +0000
Subject: Re: Re: Trying to create a colortable - what am I missing here?
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-292498@lists.php.net to get a copy of this message
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

« previous php.general (#292498) next »