self.content.seek(pos)
return "%s%8.8x%8.8x" % (hashobj.hexdigest(), width, height)
+ @property
+ def name(self):
+ return self.name_prefix + self.hashobj.name
+
class PNGHash(ImageHash):
"""A hash on the contents of a PNG image."""
+ name_prefix = "png_"
def detect(self):
if self.content.tell() < 33: # header + IHDR
class GIFHash(ImageHash):
"""A hash on the contents of the first frame of a GIF image."""
+ name_prefix = "gif_"
def detect(self):
if self.content.tell() < 10: # magic + logical dimension
return HashBlacklistContent(hashobj, boring_content)
def pnghash():
- hashobj = PNGHash(hashlib.sha512())
- hashobj = SuppressingHash(hashobj, (ValueError,))
- hashobj.name = "png_sha512"
- return hashobj
+ return SuppressingHash(PNGHash(hashlib.sha512()), (ValueError,))
def gifhash():
- hashobj = GIFHash(hashlib.sha512())
- hashobj = SuppressingHash(hashobj, (ValueError,))
- hashobj.name = "gif_sha512"
- return hashobj
+ return SuppressingHash(GIFHash(hashlib.sha512()), (ValueError,))
class ProcessingFinished(Exception):
pass