473,394 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 2645
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Oracle3001 | last post by:
Hi All, I am trying to use JAI to build a histogram of an image i have. I have posted the code below, and the error I get at runtime. I have taken the code from the offical java examples, so I am...
1
by: bleh | last post by:
....to include a removeData(datatoremove) function, to mirror the existing addData(datatoadd) function. If anybody knows of somewhere where this has been done already, if you could point me in...
2
by: kevin parks | last post by:
hi. I've been banging my head against this one a while and have asked around, and i am throwing this one out there in the hopes that some one can shed some light on what has turned out to be a...
12
by: KraftDiner | last post by:
Hi, I wrote a C++ class that implements an n dimensional histogram in C++, using stl maps and vectors. I want to code this up now in Python and would like some input from this group. The C++...
5
by: Enigma Curry | last post by:
I'm playing around with matplotlib for the first time. I'm trying to make a very simple histogram of values 1-6 and how many times they occur in a sequence. However, after about an hour of...
2
by: Daniel Nogradi | last post by:
How does one do a histogram on only a part of an image? This is what I found in the PIL documentation about histogram( ): """ im.histogram(mask) =list Returns a histogram for those parts of...
5
by: arnuld | last post by:
this is a programme that counts the "lengths" of each word and then prints that many of stars(*) on the output . it is a modified form of K&R2 exercise 1-13. the programme runs without any...
0
by: Fredrik Lundh | last post by:
aditya shukla wrote: Extracting is easy; you can do something like data = for line in open("test.txt"): line = line.split("|") data.append(float(line))
0
by: Kurt Smith | last post by:
On Fri, Jul 25, 2008 at 5:02 PM, aditya shukla <adityashukla1983@gmail.comwrote: the 'bins' argument to pylab.hist() is supposed to be an integer or a list of the bins' lower edges. The default...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.