diff options
author | Helmut Grohne <helmut@subdivi.de> | 2021-12-29 15:24:34 +0100 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2021-12-29 15:24:34 +0100 |
commit | c2b5909eff090ebb3f19ab88308f0cc7b913157e (patch) | |
tree | 4188260ea9f0f0783bf730a071a38d0784385ce1 /dedup | |
parent | 2cb95eb8c68a692b0abb535925e8b55175285ea4 (diff) | |
download | debian-dedup-c2b5909eff090ebb3f19ab88308f0cc7b913157e.tar.gz |
ImageHash: gain a name property
Instead of retroactively attaching a name to an ImageHash, autogenerate
it via a property. Doing so also simplifies static type checking.
Diffstat (limited to 'dedup')
-rw-r--r-- | dedup/image.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/dedup/image.py b/dedup/image.py index 2e64e6b..91321f4 100644 --- a/dedup/image.py +++ b/dedup/image.py @@ -69,9 +69,14 @@ class ImageHash: 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 @@ -86,6 +91,7 @@ class PNGHash(ImageHash): 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 |