How can I get GIF histogram data using PHP?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • firewoodtim

    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.
  • Oli Filth

    #2
    Re: How can I get GIF histogram data using PHP?

    firewoodtim said the following on 08/01/2006 18:53:[color=blue]
    > 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?[/color]

    Load the image with imagecreatefrom gif(). 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

    Comment

    • firewoodtim

      #3
      Re: How can I get GIF histogram data using PHP?

      On Mon, 09 Jan 2006 01:39:26 GMT, Oli Filth <catch@olifilth .co.uk>
      wrote:
      [color=blue]
      >firewoodtim said the following on 08/01/2006 18:53:[color=green]
      >> 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?[/color]
      >
      >Load the image with imagecreatefrom gif(). 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.[/color]

      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)

      Comment

      • firewoodtim

        #4
        Re: How can I get GIF histogram data using PHP?

        On Mon, 09 Jan 2006 19:08:47 GMT, firewoodtim <tim@ironwork.c om>
        wrote:
        [color=blue]
        >On Mon, 09 Jan 2006 01:39:26 GMT, Oli Filth <catch@olifilth .co.uk>
        >wrote:
        >[color=green]
        >>firewoodtim said the following on 08/01/2006 18:53:[color=darkred]
        >>> 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?[/color]
        >>
        >>Load the image with imagecreatefrom gif(). 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.[/color]
        >
        >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_pixel s => color_code (ie #rrggbb)[/color]

        correction:
        The array would actually be structured:
        palette_index => array(#_pixels, #rrggbb);

        Comment

        • Oli Filth

          #5
          Re: How can I get GIF histogram data using PHP?

          firewoodtim said the following on 09/01/2006 19:08:[color=blue]
          > On Mon, 09 Jan 2006 01:39:26 GMT, Oli Filth <catch@olifilth .co.uk>
          > wrote:
          >[color=green]
          >>firewoodtim said the following on 08/01/2006 18:53:
          >>[color=darkred]
          >>>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?[/color]
          >>
          >>Load the image with imagecreatefrom gif(). 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.[/color]
          >
          > 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?[/color]

          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

          Comment

          • firewoodtim

            #6
            Re: How can I get GIF histogram data using PHP?

            On Mon, 09 Jan 2006 21:00:18 GMT, Oli Filth <catch@olifilth .co.uk>
            wrote:
            [color=blue]
            >firewoodtim said the following on 09/01/2006 19:08:[color=green]
            >> On Mon, 09 Jan 2006 01:39:26 GMT, Oli Filth <catch@olifilth .co.uk>
            >> wrote:
            >>[color=darkred]
            >>>firewoodti m 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 imagecreatefrom gif(). 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.[/color]
            >>
            >> 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?[/color]
            >
            >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...[/color]

            Oli,
            Thanks for the info. That does help me a lot. It looks like
            imagecolorsfori ndex() provides the missing link.

            Comment

            Working...