imagecolorstotal() function in PHP



The imagecolorstotal() function gets the count of colors in an image's palette

Syntax

imagecolorstotal (img)

Parameters

  • img: Image created with imagecreatetruecolor().

Return

The imagecolorstotal() function returns the number of colors in an image palette.

Example

The following is an example

 Live Demo

<?php
   $img = imagecreatefromgif('https://www.tutorialspoint.com/images/html.gif');
   echo 'Number of Colors = ' . imagecolorstotal($img);
   imagedestroy($img);
?>

Output

The following is the output:

Number of Colors = 128
Updated on: 2019-12-31T07:47:13+05:30

63 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements