array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.imagecolorstotal.php', 1 => 'imagecolorstotal', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'GD 和图像处理 函数', ), 'prev' => array ( 0 => 'function.imagecolorsforindex.php', 1 => 'imagecolorsforindex', ), 'next' => array ( 0 => 'function.imagecolortransparent.php', 1 => 'imagecolortransparent', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/image/functions/imagecolorstotal.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
imagecolorstotal — 取得图像调色板中的颜色数量
返回指定图像调色板中的颜色数量,真彩色图像为 0。
示例 #1 使用 imagecolorstotal() 获取图像中的颜色总数
<?php
// Create image instance
$im = imagecreatefromgif('php.gif');
echo 'Total colors in image: ' . imagecolorstotal($im);
// Free image
imagedestroy($im);
?>
以上示例的输出类似于:
Total colors in image: 128