TechniqueUse 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); ?> CommentsThe 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). |