" . $x . $image . " contains " . $colourCount . " colours.
"; //} else { $img = @imagecreatefromstring(file_get_contents($image)); //} if ($upload) { unlink($image); } if (!$img) { //$x = " error "; $prefix.="" . $x . $image . " contains " . $colourCount . " colours.
"; } else { $colourCount = imagecolorstotal($img); if ($colourCount == 0) { // with code below, thanks to https://stackoverflow.com/questions/25400805/how-to-know-howmany-colors-are-exist-in-the-image //echo "yes"; //exit; $w = imagesx($img); $h = imagesy($img); // capture the raw data of the image ob_start(); imagegd2($img, null, $w); $data = ob_get_clean(); $totalLength = strlen($data); // calculate the length of the actual pixel data // from that we can derive the header size $pixelDataLength = $w * $h * 4; $headerLength = $totalLength - $pixelDataLength; // use each four-byte segment as the key to a hash table $counts = array(); for($i = $headerLength; $i < $totalLength; $i += 4) { $pixel = substr($data, $i, 4); $count =& $counts[$pixel]; $count += 1; } $colourCount = count($counts); //echo $colourCount; if ($byes) { $nhead=str_replace(">" . $image . " contains " . $colourCount . " colours.
" . $image . " contains " . $colourCount . " colours.
" . $image . " contains " . $colourCount . " colours.
" . $image . " contains " . $colourCount . " colours.