Still, working on it. Here is the latest script I am using:
PHP Code:
<pre><?php
$filename = 'http://www.animeviews.com/images/pops/maincontent1.JPG';
$im = imagecreatefromjpeg($filename);
imagetruecolortopalette($im, false, 255);
$a= imagecolorstotal($im);
echo"$a";
$g=$a;
$a++;
$b=0;
$c=0;
$d=0;
$e=0;
while ($b<$a){
$x=rand(0,255);
$y=rand(0,255);
$z=rand(0,255);
$result = imagecolorclosest($im, $x, $y, $z);
$c++;
##if ($c>255){$d++;$c=255;}
##if ($d>255){$e++;$d=255;}
$e++;
$result = imagecolorsforindex($im, $result);
$result = "({$result['red']}, {$result['green']}, {$result['blue']})";
$arry[]="$result";
$arry=array_unique($arry);
$b=count($arry);
if ($b>254){break;}
if ($e>10000){break;}
}
print_r($arry);Echo"<br><br>$b";
?></pre>
It will generate random colors to check until it either finds all of the colors or goes through 10000 tries; which ever comes first.
EDIT: The following is better:
PHP Code:
<pre><?php
$filename = 'http://www.animeviews.com/images/pops/maincontent1.JPG';
$im = imagecreatefromjpeg($filename);
imagetruecolortopalette($im, false, 25);
$a= imagecolorstotal($im);
echo"$a";
$e=0;
while ($b<$a){
$x=rand(0,255);
$y=rand(0,255);
$z=rand(0,255);
$result = imagecolorclosest($im, $x, $y, $z);
$e++;
$result=imagecolorsforindex($im, $result);
$result="({$result['red']}, {$result['green']}, {$result['blue']})";
$arry[]="$result";
$arry=array_unique($arry);
$b=count($arry);
if ($e>10000){break;}
}
asort($arry);
print_r($arry);Echo"<br><br>
number of colors in image=$a
<br>number of colors located=$b
<br>Number of tries=$e<br>";
?></pre>
It seems that one of my errors was that imagecolorstotal() determines how many colors are in the palette; not how many colors were used from the palette.
On a side note I am not all that good at using the semicolon in a sentence :?.
Bookmarks