diff options
author | Paweł Jastrzębski <pawelj@vulturis.eu> | 2014-01-24 22:43:24 +0100 |
---|---|---|
committer | Paweł Jastrzębski <pawelj@vulturis.eu> | 2014-01-24 22:43:24 +0100 |
commit | 3bb8cc77788f7822ceb77af0f9e01223c4a514f5 (patch) | |
tree | 88afc44cc948f4aa89c7f3acd14f1f213dfefc95 /kcc/image.py | |
parent | Great Index: Slugification fix (diff) | |
download | kcc-3bb8cc77788f7822ceb77af0f9e01223c4a514f5.tar.gz kcc-3bb8cc77788f7822ceb77af0f9e01223c4a514f5.tar.bz2 kcc-3bb8cc77788f7822ceb77af0f9e01223c4a514f5.zip |
Great Index: Using MD5 checksums instead file paths.
Performance impact is negligible, it simplify the code and is much more error resistant.
Diffstat (limited to 'kcc/image.py')
-rwxr-xr-x | kcc/image.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/kcc/image.py b/kcc/image.py index edde36d..b3016cd 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -21,10 +21,22 @@ __copyright__ = '2012-2013, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jas __docformat__ = 'restructuredtext en' import os +from hashlib import md5 from functools import reduce from PIL import Image, ImageOps, ImageStat, ImageChops +def md5Checksum(filePath): + with open(filePath, 'rb') as fh: + m = md5() + while True: + data = fh.read(8192) + if not data: + break + m.update(data) + return m.hexdigest() + + class ProfileData: def __init__(self): pass @@ -146,7 +158,7 @@ class ComicPage: else: filename += ".jpg" self.image.save(filename, "JPEG", optimize=1) - return [filename, flags] + return [md5Checksum(filename), flags] else: return None except IOError as e: |