imagetruecolortopalette 


gd apg

CONVERT a true color image to a palette image.





DITHERING

is a technique used in computer graphics to create the illusion of color depth in images whose palette has a limited number of colors.


If $dither = TRUE then dithering will be used which will result in a more speckled image but with better color approximation.

This function returns TRUE on success or FALSE on failure.



<?php

bool imagetruecolortopalette 
GdImage $imagebool $ditherint $num_colors )

where,

$image An image identifier

$dither 
To control if the image will be dithered or not

$num_colors 
The maximun number of colors that 
                                     should be retained in the palette

?>

  $image   


The image identifier.



  $dither   


To control if the image will be dithered or not.



  $num_colors   


The maximun number of colors that should be retained in the palette.



  1 EXERCISE   

<?php

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

$lang 'en';

$tst_img01 "png/PNG 081 01.png";

$dst_img01 "gif/GIF 027 01.gif";

$dith TRUE;
$colors 256;

$id_wv01 imagecreatefrompng($tst_img01);

$is_tc imageistruecolor($id_wv01);

if(
$is_tc == FALSE)
{
$en '<br><br>Is not a TRUECOLOR IMAGE';

echo 
$tst_img01 . $$lang?>
<br><br><img src="<?php echo $tst_img01?>"
alt="<?php echo $tst_img01?>" width="400"><br><br><br><br>

<?php
}
else
{
$en '<br><br>TRUECOLOR IMAGE';

echo 
$tst_img01 . $$lang?>
<br><br><img src="<?php echo 
$tst_img01?>" alt="<?php echo $tst_img01?>" width="400">
<br><br><br><br>

<?php

imagetruecolortopalette
($id_wv01$dith$colors);

imagegif($id_wv01$dst_img01);

$en '<br><br>PALETTE IMAGE';

echo 
$dst_img01 . $$lang?>
<br><br><img src="<?php echo 
$dst_img01?>" alt="<?php echo $dst_img01?>" width="400"><br>

<?php
}

?> 

 RESULT   

PNG 081 01.png

TRUECOLOR IMAGE

PNG 081 01.png apr



GIF 027 01.gif

PALETTE IMAGE

GIF 027 01.gif apr