469,354 Members | 2,255 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,354 developers. It's quick & easy.

How can I get GIF histogram data using PHP?

I want to analyze a GIF file and retrieve the histogram data on the
image (pixel quantity and color symbol for each color in the file.)
Does anyone know how to use PHP to do this? I've looked through the
PHP documentation, the GD image library, and the ImageMagick
command-line imaging system and found very little that I could use.

The best thing I've found so far is an "identify -verbose" command
from ImageMagick that gives the data I need, mixed in with a heap of
other information about the GIF image. If I use that and the IM folks
change their report format, it will break my script to extract the
information. I need a function or script designed to generate only
histogram data directly from the GIF file.
Jan 8 '06 #1
5 2466
firewoodtim said the following on 08/01/2006 18:53:
I want to analyze a GIF file and retrieve the histogram data on the
image (pixel quantity and color symbol for each color in the file.)
Does anyone know how to use PHP to do this?


Load the image with imagecreatefromgif(). Then loop through each pixel
of the image, call imagecolorat() to obtain the palette index for that
pixel, and increment a tally for each palette index.

These functions are described in the PHP manual.
--
Oli
Jan 9 '06 #2
On Mon, 09 Jan 2006 01:39:26 GMT, Oli Filth <ca***@olifilth.co.uk>
wrote:
firewoodtim said the following on 08/01/2006 18:53:
I want to analyze a GIF file and retrieve the histogram data on the
image (pixel quantity and color symbol for each color in the file.)
Does anyone know how to use PHP to do this?


Load the image with imagecreatefromgif(). Then loop through each pixel
of the image, call imagecolorat() to obtain the palette index for that
pixel, and increment a tally for each palette index.

These functions are described in the PHP manual.


I did what you suggested, and it worked as predicted, but that still
leaves me with just the palette index for each color. i still need to
correlate that with the palette itself, in order to get the actual
color value. Can you advise me on how to get a GIF's palatte?

I need to wind up with an array, with the configuration:
key => value
num_of_pixels => color_code (ie #rrggbb)
Jan 9 '06 #3
On Mon, 09 Jan 2006 19:08:47 GMT, firewoodtim <ti*@ironwork.com>
wrote:
On Mon, 09 Jan 2006 01:39:26 GMT, Oli Filth <ca***@olifilth.co.uk>
wrote:
firewoodtim said the following on 08/01/2006 18:53:
I want to analyze a GIF file and retrieve the histogram data on the
image (pixel quantity and color symbol for each color in the file.)
Does anyone know how to use PHP to do this?


Load the image with imagecreatefromgif(). Then loop through each pixel
of the image, call imagecolorat() to obtain the palette index for that
pixel, and increment a tally for each palette index.

These functions are described in the PHP manual.


I did what you suggested, and it worked as predicted, but that still
leaves me with just the palette index for each color. i still need to
correlate that with the palette itself, in order to get the actual
color value. Can you advise me on how to get a GIF's palatte?

I need to wind up with an array, with the configuration:
key => value
num_of_pixels => color_code (ie #rrggbb)


correction:
The array would actually be structured:
palette_index => array(#_pixels, #rrggbb);
Jan 9 '06 #4
firewoodtim said the following on 09/01/2006 19:08:
On Mon, 09 Jan 2006 01:39:26 GMT, Oli Filth <ca***@olifilth.co.uk>
wrote:
firewoodtim said the following on 08/01/2006 18:53:
I want to analyze a GIF file and retrieve the histogram data on the
image (pixel quantity and color symbol for each color in the file.)
Does anyone know how to use PHP to do this?


Load the image with imagecreatefromgif(). Then loop through each pixel
of the image, call imagecolorat() to obtain the palette index for that
pixel, and increment a tally for each palette index.

These functions are described in the PHP manual.


I did what you suggested, and it worked as predicted, but that still
leaves me with just the palette index for each color. i still need to
correlate that with the palette itself, in order to get the actual
color value. Can you advise me on how to get a GIF's palatte?


Dude, did you take any time *at all* to have a look at the PHP manual
for the GD functions? If you'd looked at the manual page for
imagecolorat(), for instance, you would've seen some "See also" links,
some of which you might have found useful...

--
Oli
Jan 9 '06 #5
On Mon, 09 Jan 2006 21:00:18 GMT, Oli Filth <ca***@olifilth.co.uk>
wrote:
firewoodtim said the following on 09/01/2006 19:08:
On Mon, 09 Jan 2006 01:39:26 GMT, Oli Filth <ca***@olifilth.co.uk>
wrote:
firewoodtim said the following on 08/01/2006 18:53:

I want to analyze a GIF file and retrieve the histogram data on the
image (pixel quantity and color symbol for each color in the file.)
Does anyone know how to use PHP to do this?

Load the image with imagecreatefromgif(). Then loop through each pixel
of the image, call imagecolorat() to obtain the palette index for that
pixel, and increment a tally for each palette index.

These functions are described in the PHP manual.


I did what you suggested, and it worked as predicted, but that still
leaves me with just the palette index for each color. i still need to
correlate that with the palette itself, in order to get the actual
color value. Can you advise me on how to get a GIF's palatte?


Dude, did you take any time *at all* to have a look at the PHP manual
for the GD functions? If you'd looked at the manual page for
imagecolorat(), for instance, you would've seen some "See also" links,
some of which you might have found useful...


Oli,
Thanks for the info. That does help me a lot. It looks like
imagecolorsforindex() provides the missing link.
Jan 9 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Oracle3001 | last post: by
1 post views Thread by bleh | last post: by
2 posts views Thread by kevin parks | last post: by
12 posts views Thread by KraftDiner | last post: by
2 posts views Thread by Daniel Nogradi | last post: by
5 posts views Thread by arnuld | last post: by
reply views Thread by Kurt Smith | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.