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

2009-05-12 Thread Thodoris



דניאל דנון wrote:

I've tried to make a color table, but I am missing something. not in the
color-table-code itself, but in somewhere else... I just can't find...


untested but try..

// 4096*4096 = 16777216 = FF+1
$im = imagecreate(4096, 4096);
$white = imagecolorallocate($im, 0, 0, 0);
$r = $g = $b = $x = $y =  0;
$max = 255;
while ($r = $max) {
  while ($g = $max) {
while ($b = $max) {
  $n = imagecolorallocate($im, $r, $g, $b);
  imagesetpixel($im, $x, $y, $n);
  $x = $x == 4096 ? 0 : $x+1;
  $y = $y == 4096 ? 0 : $y+1;
  $b++;
}
   $b = 0;
   $g++;
  }
  $g = 0;
  $r++;
}
header(Content-Type: image/png);
imagepng($im);
imagedestroy($im);




Never used image manipulation with PHP but this is giving me a black image.

--
Thodoris


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



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

2009-05-12 Thread Peter Ford
Thodoris wrote:
 
 דניאל דנון wrote:
 I've tried to make a color table, but I am missing something. not in the
 color-table-code itself, but in somewhere else... I just can't find...

 untested but try..

 // 4096*4096 = 16777216 = FF+1
 $im = imagecreate(4096, 4096);
 $white = imagecolorallocate($im, 0, 0, 0);
 $r = $g = $b = $x = $y =  0;
 $max = 255;
 while ($r = $max) {
   while ($g = $max) {
 while ($b = $max) {
   $n = imagecolorallocate($im, $r, $g, $b);
   imagesetpixel($im, $x, $y, $n);
   $x = $x == 4096 ? 0 : $x+1;
   $y = $y == 4096 ? 0 : $y+1;
   $b++;
 }
$b = 0;
$g++;
   }
   $g = 0;
   $r++;
 }
 header(Content-Type: image/png);
 imagepng($im);
 imagedestroy($im);


 
 Never used image manipulation with PHP but this is giving me a black image.
 


You probably need
$im = imagecreatetruecolor(4096,4096);

Also be aware that creating a truecolor image 4096 pixels square is going to
take a LOT of memory, and it will take a while to download to the client, AND it
is 4096 pixels square! That's a fair bit bigger than most screens...

I suspect the OP is going to have to rethink this...
-- 
Peter Ford  phone: 01580 89
Developer   fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

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



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

2009-05-12 Thread Thodoris




Thodoris wrote:
  

דניאל דנון wrote:
  

I've tried to make a color table, but I am missing something. not in the
color-table-code itself, but in somewhere else... I just can't find...


untested but try..

// 4096*4096 = 16777216 = FF+1
$im = imagecreate(4096, 4096);
$white = imagecolorallocate($im, 0, 0, 0);
$r = $g = $b = $x = $y =  0;
$max = 255;
while ($r = $max) {
  while ($g = $max) {
while ($b = $max) {
  $n = imagecolorallocate($im, $r, $g, $b);
  imagesetpixel($im, $x, $y, $n);
  $x = $x == 4096 ? 0 : $x+1;
  $y = $y == 4096 ? 0 : $y+1;
  $b++;
}
   $b = 0;
   $g++;
  }
  $g = 0;
  $r++;
}
header(Content-Type: image/png);
imagepng($im);
imagedestroy($im);


  

Never used image manipulation with PHP but this is giving me a black image.





You probably need
$im = imagecreatetruecolor(4096,4096);
  


Still doesn't work...
Now the result is an almost black image with a yellow-white line in the 
middle.



Also be aware that creating a truecolor image 4096 pixels square is going to
take a LOT of memory, and it will take a while to download to the client, AND it
is 4096 pixels square! That's a fair bit bigger than most screens...
  


It was necessary to increase max execution time to something big above 4 
minutes.



I suspect the OP is going to have to rethink this...
  


Still curious about the right script though (if this is possible of course).

--
Thodoris



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

2009-05-12 Thread Thodoris



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