By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

Exctract GIF comment from image

P: n/a
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.
Mar 11 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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 <mi*********@gmail.com>
http://pythonwise.blogspot.com
Mar 11 '08 #2

P: n/a
2008/3/11, wi***@gmx.com <wi***@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.

--
http://mail.python.org/mailman/listinfo/python-list
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_comments(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(blocksize)
else:
fobj.read(blocksize)

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_comments(gif)

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

--
-- Guilherme H. Polo Goncalves
Mar 11 '08 #3

P: n/a
On 11 Mrz., 18:39, "Guilherme Polo" <ggp...@gmail.comwrote:
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*
Mar 12 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.