473,382 Members | 1,441 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,382 software developers and data experts.

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.
Mar 11 '08 #1
3 1864
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: raver2046 | last post by:
here i have a link <a href="http://raver2046.ath.cx/CV/">cv network admin</a> how to extract "cv network admin" here is the code i have find to exctract link but not title of link ...
1
by: Bob | last post by:
Dears, I am trying to search and replace strings with regex. The string is identified by a keyword : IDImage("1M234567"); DescriptionImage("Desc of the Image 1"); I want to exctract the...
0
by: Jeffrey Barish | last post by:
I am trying to use PIL to add a comment to an image. I have never used PIL before, but I discovered that it is possible to print an existing comment with the following: im =...
29
by: dbhbarton | last post by:
Had a thought that's grown on me. No idea if it's original or not- too inexperienced in programming- but I guess there's no harm floating it out there. Python wins big on readability, and...
1
by: Joe Cool | last post by:
I am attempting to add a function to an application I am working on to modify the JPEG Comment in a Jpeg image file. I can retrieve the JPEG Comment with no problem. The problem is modifying it....
2
by: raylopez99 | last post by:
I can't get the below code to work, no matter how many times I change it. I do have the Image file, Image1, created (in another method), and using "hard coding" I can save it (it's a filled...
5
by: peacemaker2008 | last post by:
Hi all the problem i am facing is different, i am trying to display images form database,i m giving code that i wrote $sql = "select * from upload "; ...
1
by: neovantage | last post by:
Hey all, I am using a PHP script which creates headings at run time in a sense at page execution. I am stuck a with a very little problem which i am sure i will have the solution from experts. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.