[Image-SIG] Re: gimp-2.0 palette
Fredrik Lundh
fredrik at pythonware.com
Tue Sep 7 13:52:09 CEST 2004
colliera at ukzn.ac.za wrote:
> has anyone tried to import gimp-2 palettes using the GimpPaletteFile
> module?
> i don't imagine that it would be too difficult to cater for both?
I've attached a patch.
</F>
Index: PIL/GimpPaletteFile.py
===================================================================
--- PIL/GimpPaletteFile.py (revision 1969)
+++ PIL/GimpPaletteFile.py (working copy)
@@ -20,1 +20,1 @@
-import string
+import re, string
##
# File handler for GIMP's palette format.
@@ -37,13 +38,13 @@
if not s:
break
+ # skip fields and comment lines
+ if re.match("\w+:|#", s):
+ continue
if len(s) > 100:
raise SyntaxError, "bad palette file"
- if s[0] == "#":
- continue
-
- v = tuple(map(string.atoi, string.split(s)[:3]))
+ v = tuple(map(int, string.split(s)[:3]))
if len(v) != 3:
raise ValueError, "bad palette entry"
More information about the Image-SIG
mailing list