Simple PNG validator.
git-svn-id: http://svn.robofab.com/branches/ufo3k@369 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c
This commit is contained in:
parent
b579bdaeae
commit
bed4f7e109
@ -673,6 +673,28 @@ def imageValidator(value):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def pngValidator(path=None, data=None, fileObj=None):
|
||||||
|
"""
|
||||||
|
Version 3+.
|
||||||
|
|
||||||
|
This checks the signature of the image data.
|
||||||
|
"""
|
||||||
|
print path
|
||||||
|
assert path is not None or data is not None or fileObj is not None
|
||||||
|
if path is not None:
|
||||||
|
f = open(path, "rb")
|
||||||
|
signature = f.read(8)
|
||||||
|
f.close()
|
||||||
|
elif data is not None:
|
||||||
|
signature = data[:8]
|
||||||
|
elif fileObj is not None:
|
||||||
|
pos = fileObj.tell()
|
||||||
|
signature = fileObj.read(8)
|
||||||
|
fileObj.seek(pos)
|
||||||
|
if signature != "\x89PNG\r\n\x1a\n":
|
||||||
|
return False, "Image does not begin with the PNG signature."
|
||||||
|
return True, None
|
||||||
|
|
||||||
# -------------------
|
# -------------------
|
||||||
# layercontents.plist
|
# layercontents.plist
|
||||||
# -------------------
|
# -------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user