Jump to content


This topic is now archived and is closed to further replies.


how to count colors on handle ?

Recommended Posts

$whatever = imagecreatefrompng('somefile.png');

now i want to know how many colors are actually in this file, not how many colors is this format capable to contain, like truecolor etc... not this

in my script i use program to make some png images from command line (a full-length rendering of a html page to png), but this program has very annoying bug that it sometimest returns a blank image, so i want to track somehow these images having only one fill color

how to do this ? many graphical programs have this function ?

Share this post

Link to post
Share on other sites
The image files themselves don't contain that data explicitly. You would need to find a way to examine each pixel and build the data. I'm not sure about PNG, but with something like jpeg that may not be even possible because of the way the data is stored there is no individual pixel assignments. Even if all of this is possible, it would be a huge resource hog.

I would suggest you use the size (data size not dimensions) as a way of determining if the image is blank or not. That would be very easy to determine.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.