Exctract GIF comment from image

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wingi@gmx.com

    #1

    Exctract GIF comment from image

    Hi,

    simple question: The PIL does not support reading the optional
    description in GIF Images.

    http://www.pythonware.com/library/pi...format-gif.htm

    After some reasearch I could not find a python solution for this, any
    suggestions?

    Thanx, Wingi.
  • Miki

    #2
    Re: Exctract GIF comment from image

    Hello Wingi,
    simple question: The PIL does not support reading the optional
    description in GIF Images.
    >
    http://www.pythonware.com/library/pi...format-gif.htm
    >
    After some reasearch I could not find a python solution for this, any
    suggestions?
    Use ImageMagick (www.imagemagick.org), "identify -verbose <image>"
    should have the comments somewhere
    in the output.
    There also a python binding to ImageMagick but I have no experience
    with it.

    HTH,
    --
    Miki <miki.tebeka@gm ail.com>
    If it won't be simple, it simply won't be. [Hire me, source code]

    Comment

    • Guilherme Polo

      #3
      Re: Exctract GIF comment from image

      2008/3/11, wingi@gmx.com <wingi@gmx.com> :
      Hi,
      >
      simple question: The PIL does not support reading the optional
      description in GIF Images.
      >
      http://www.pythonware.com/library/pi...format-gif.htm
      >
      After some reasearch I could not find a python solution for this, any
      suggestions?
      >
      Thanx, Wingi.
      >
      --

      >
      I did a quick thing here, try it and check if it solves the problem for you:

      import os
      import sys
      import struct

      def extract_comment s(giffile):
      fobj = open(giffile, 'rb')

      giftype = fobj.read(6)
      pf = struct.unpack(' <hhBBB', fobj.read(7))[2]
      if pf & 0x80:
      pallete_size = 2 << (pf & 0x07)
      fobj.read(3 * pallete_size)
      # finished reading header

      fsize = os.stat(giffile ).st_size
      while fobj.tell() != fsize:
      mark = ord(fobj.read(1 ))

      if mark == 0x21: # gif extension
      label = ord(fobj.read(1 ))
      is_comment = label == 254

      # read the extension block
      blocksize = ord(fobj.read(1 ))
      while blocksize:
      if is_comment:
      print fobj.read(block size)
      else:
      fobj.read(block size)

      blocksize = ord(fobj.read(1 ))

      def main(args):
      if len(args) < 2:
      print "Usage: %s <gif file..." % args[0]
      sys.exit(0)

      for gif in args[1:]:
      extract_comment s(gif)

      if __name__ == "__main__":
      main(sys.argv)

      --
      -- Guilherme H. Polo Goncalves

      Comment

      • wingi@gmx.com

        #4
        Re: Exctract GIF comment from image

        On 11 Mrz., 18:39, "Guilherme Polo" <ggp...@gmail.c omwrote:
        2008/3/11, wi...@gmx.com <wi...@gmx.com> :
        >
        Hi,
        >
        simple question: ThePILdoes not support reading the optional
        description in GIF Images.
        >
        >
        I did a quick thing here, try it and check if it solves the problem for you:
        >
        Wow - thanx for the fast answer!

        Yes it works and can use it ;-)

        *smile*

        Comment

        Working...