imagecolorclosesthwb 


gd apg

GET the index of the color which has the hue, white and blackness nearest the given color.





This function get the index of an specific pixel color $image..





$image symbolized by a identifier returned by one of the image creation functions, such as imagecreate or imagecreatetruecolor.

0 ≤ $red ≤ 255 = 0x00 ≤ $red ≤ 0xff = 0x00 ≤ $red ≤ 0xFF


0 ≤ $green ≤ 255 = 0x00 ≤ $green ≤ 0xff = 0x00 ≤ $green ≤ 0xFF


0 ≤ $blue ≤ 255 = 0x00 ≤ $blue ≤ 0xff= 0x00 ≤ $blue ≤ 0xFF


This function is available on Windows since PHP 5.3.0.


HWB

is short for HUE + WHITENESS + BLACKNESS.


HUE

controls the color description in the visible spectrum.


WHITENESS  or  SATURATION

defines the degree of bleaching of a color.


BLACKNESS

defines the degree of darkening of a color.



<?php

int imagecolorclosesthwb 
GdImage $image
                                                     
int $red
                                                     
int $green
                                                     
int $blue )

where,

$image The image identifier 

$red 
The value of red component color 

$green 
The value of green component color

$blue 
The value of blue component color

?>
 

  $image   


The image identifier.



  $red   


The value of red component of color.



  $green   


The value of green component of color.



  $blue   


The value of blue component of color.



  1 EXERCISE   

<?php

// RUN this code several times

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

$lang 'en';

$org_file01 "png/PNG 038 01 Asklepion-Pergamo.png";

$palsrc01 "png/PNG 038 01 Asklepion-Pergamo-t.png";

$palfnd01 "png/PNG 038 01 Asklepion-Pergamo-c.png";

$palcolorndx01 mt_rand(12222213999988);

if(
file_exists($org_file01))
{
echo 
$org_file01?><br><br>
<img src="<?php echo $org_file01?>"
 alt="<?php echo $org_file01?>
 title="TRUECOLOR IMAGE" width="400"><br><br>

<?php
 $imaskl01 
imagecreatefrompng ($org_file01);
 
$palndxcolor01 
 
imagecolorsforindex ($imaskl01$palcolorndx01);
 
 
$red01 $palndxcolor01['red'];
 
$green01 $palndxcolor01['green'];
 
$blue01 $palndxcolor01['blue'];
 
 
$pt 'Índice da Paleta: ' $palcolorndx01 '<br>Cor: ';
 
$en 'Palette Index: ' $palcolorndx01 '<br> Color: ';
 echo 
$palsrc01 .'<br><br>';
 
$RGBsrc01 'RGB ( ' $red01 ', ' $green01 ', ' $blue01 ' )';
 
 echo 
'' . $$lang $RGBsrc01 '<br>';
  
 
$imtaskl01 imagecreate (imagesx($imaskl01),60);
 
imagecolorallocate($imtaskl01$red01$green01$blue01);
 
imagepng($imtaskl01$palsrc01);
 
 
?> <br>

<img src="<?php echo $palsrc01?>"
 alt="<?php echo $palsrc01?>
 title="<?php echo $palsrc01?>" width="400"><br><br>
 <?php
 $hwb_color_ndx01 

 
imagecolorclosesthwb ($imaskl01$red01
                                                        
$green01
                                                        
$blue01);
 
  
$palndxhbdcolor01 
  
imagecolorsforindex ($imaskl01$hwb_color_ndx01);
  
 
$hwbred01 $palndxhbdcolor01['red'];
 
$hwbgreen01 $palndxhbdcolor01['green'];
 
$hwbblue01 $palndxhbdcolor01['blue'];
 
 
$pt 'Índice HWB da Paleta: ' $hwb_color_ndx01 '<br>Cor: ';
 
$en 'HWB Palette Index: ' $hwb_color_ndx01 '<br>Color: ';
 
 
$RGBhwb01 'RGB ( ' $hwbred01 ', ' 
                                    
$hwbgreen01 ', ' $hwbblue01 ' )';
 echo 
$palfnd01 '<br><br>';
 echo 
'' . $$lang $RGBhwb01 '<br>';
 
 
$imcaskl01 imagecreate (imagesx($imaskl01),60);
 
imagecolorallocate($imcaskl01$hwbred01
                                                     
$hwbgreen01
                                                     
$hwbblue01);
 
imagepng($imcaskl01$palfnd01);
 
  
?>
 <br>
<img src="<?php echo $palfnd01?>"
 alt="<?php echo $palfnd01?>
 title="<?php echo $palfnd01?>" width="400"><br><br>
 <?php
}
else
{
$pt 'Imagem não disponível';
$en 'Image not available';
echo 
'' . $$lang '';
}

?>


 RESULT   

PNG 038 01 Asklepion-Pergamo.png

EXISTING TRUECOLOR IMAGE

PNG 038 01 Asklepion-Pergamo.png apr

Every new execution a new result can be obtained.

DO THE TEST YOURSELF.



  2 EXERCISE   

<?php

// RUN this code several times

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

// $lang = 'pt';
$lang 'en';

$org_file02 "gif/GIF 019 02 Asklepion-Pergamo.gif";

$palsrc02 "gif/GIF 019 02 Asklepion-Pergamo-t.gif";

$palfnd02 "gif/GIF 019 02 Asklepion-Pergamo-c.gif";

$palcolorndx02 mt_rand(10170);

if(
file_exists($org_file02))
{
echo 
$org_file02?><br><br>
<img src="<?php echo $org_file02?>"
 alt="<?php echo $org_file02?>" title="PALETTE IMAGE" width="400"><br><br>

<?php
 $imaskl02 
imagecreatefromgif ($org_file02);
 
$palndxcolor02 
 
imagecolorsforindex ($imaskl02$palcolorndx02);
 
 
$red02 mt_rand(1255);
 
$green02 mt_rand(1255);
 
$blue02 mt_rand(1255);
 
 
$pt 'Índice da Paleta: ' $palcolorndx02 '<br>Cor: ';
 
$en 'Palette Index: ' $palcolorndx02 '<br> Color: ';
 echo 
$palsrc02 .'<br><br>';
 
$RGBsrc02 'RGB ( ' $red02 ', ' 
                                   
$green02 ', ' 
                                   
$blue02 ' )';
 
 echo 
'' . $$lang $RGBsrc02 '<br>';
  
 
$imtaskl02 imagecreate (imagesx($imaskl02),60);
 
imagecolorallocate($imtaskl02$red02
                                                   
$green02
                                                   
$blue02);
 
imagegif($imtaskl02$palsrc02);
 
 
?>
 <br>
<img src="<?php echo $palsrc02?>"
 alt="<?php echo $palsrc02?>
 title="<?php echo $palsrc02?>" width="400"><br><br>
 <?php
 $hwb_color_ndx02 

 
imagecolorclosesthwb ($imaskl02$red02
                                                        
$green02
                                                        
$blue02);
 
  
$palndxhbdcolor02 
  
imagecolorsforindex ($imaskl02$hwb_color_ndx02);
  
 
$hwbred02 $palndxhbdcolor02['red'];
 
$hwbgreen02 $palndxhbdcolor02['green'];
 
$hwbblue02 $palndxhbdcolor02['blue'];
 
 
$pt 'Índice HWB da Paleta: ' $hwb_color_ndx02 '<br>Cor: ';
 
$en 'HWB Palette Index: ' $hwb_color_ndx02 '<br>Color: ';
 
 
$RGBhwb02 'RGB ( ' $hwbred02 ', ' 
                                    
$hwbgreen02 ', ' $hwbblue02 ' )';
 echo 
$palfnd02 '<br><br>';
 echo 
'' . $$lang $RGBhwb02 '<br>';
 
 
$imcaskl02 imagecreate (imagesx($imaskl02),60);
 
imagecolorallocate($imcaskl02
                                 
$hwbred02
                                 
$hwbgreen02$hwbblue02);
 
imagegif($imcaskl02$palfnd02);
 
  
?>
 <br>
<img src="<?php echo $palfnd02?>"
 alt="<?php echo $palfnd02?>
 title="<?php echo $palfnd02?>" width="400"><br><br>
 <?php
}
else
{
$pt 'Imagem não disponível';
$en 'Image not available';
echo 
'' . $$lang '';
}

?>


 RESULT   

GIF 019 02 Asklepion-Pergamo.gif

EXISTING PALETTE IMAGE

GIF 019 02 Asklepion-Pergamo.gif apr

Every new execution a new result can be obtained.

DO THE TEST YOURSELF.