[enh] cache images that are auto-oriented by gm
This commit is contained in:
parent
b4ddd0a0b6
commit
01bf77249d
@ -36,9 +36,26 @@ class Cache(object):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def image_needs_to_be_oritend(self, source, target, command):
|
||||||
|
if not os.path.exists(target):
|
||||||
|
return True
|
||||||
|
|
||||||
|
if target not in self.cache:
|
||||||
|
return True
|
||||||
|
|
||||||
|
cached_image = self.cache[target]
|
||||||
|
|
||||||
|
if cached_image["size"] != os.path.getsize(source) or cached_image["command"] != command:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def cache_thumbnail(self, source, target, image):
|
def cache_thumbnail(self, source, target, image):
|
||||||
self.cache[target] = {"size": os.path.getsize(source), "options": image.options}
|
self.cache[target] = {"size": os.path.getsize(source), "options": image.options}
|
||||||
|
|
||||||
|
def cache_auto_oriented_image(self, source, target, command):
|
||||||
|
self.cache[target] = {"size": os.path.getsize(source), "command": command}
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.json.dump(self.cache, open(self.cache_file_path, "w"))
|
self.json.dump(self.cache, open(self.cache_file_path, "w"))
|
||||||
|
|
||||||
|
@ -55,10 +55,16 @@ class Image(object):
|
|||||||
if not self.autoorient:
|
if not self.autoorient:
|
||||||
shutil.copyfile(source, target)
|
shutil.copyfile(source, target)
|
||||||
print source, "->", target
|
print source, "->", target
|
||||||
else:
|
return ""
|
||||||
command = "gm convert %s -strip -auto-orient %s" % (source, target)
|
|
||||||
|
command = "gm convert %s -strip -auto-orient %s" % (source, target)
|
||||||
|
|
||||||
|
if CACHE.image_needs_to_be_oritend(source, target, command):
|
||||||
print command
|
print command
|
||||||
os.system(command)
|
os.system(command)
|
||||||
|
CACHE.cache_auto_oriented_image(source, target, command)
|
||||||
|
else:
|
||||||
|
print "skipped %s since it's already generated (based on source unchanged size and images options)" % target
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user