18.6 Getting the Total Number of Colors in an Image


You need to find out how many colors there are in an image.

Technique

Use the ImageColorsTotal() function, which returns the number of colors allocated for an image:

 <?php $im = ImageCreateFromGif("some_im.gif"); echo 'some_im.gif has ' . ImageColorsTotal($im) . ' colors in its palette'; ImageDestroy($im); ?> 

Comments

The ImageColorsTotal() function returns a long with the total number of colors allocated for the given image stream. This can be useful if you need to have a certain amount of colors in an image and no more (for example, a GIF must have fewer than 256 colors).



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net