HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

imagecolorstotal

Description

The imagecolorstotal of Image for PHP find out the number of colors in an image's palette.

Syntax

imagecolorstotal(
    GdImage $image
): int

Parameters

image

A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().

Return

Returns the number of colors in the specified image's palette or 0 for truecolor images.

Examples

1 · palette

<?

$width = 100;
$height = 100;
$image = imagecreate($width, $height);

$red = 0;
$green = 0;
$blue = 0;
imagecolorallocate($image, $red, $green, $blue);

$return = imagecolorstotal($image);

echo $return;
1

2 · truecolor

<?

$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);

$return = imagecolorstotal($image);

echo $return;
0