Commit 5fbbd419 authored by Gero Müller's avatar Gero Müller
Browse files

fix pil thumbnails

parent 250cee56
...@@ -13,9 +13,9 @@ import shutil ...@@ -13,9 +13,9 @@ import shutil
import stat import stat
import subprocess import subprocess
try: try:
import Image import Image
import ImageFilter
HAVE_PIL = True HAVE_PIL = True
except: except:
HAVE_PIL = False HAVE_PIL = False
...@@ -389,11 +389,15 @@ class FileSystem(object): ...@@ -389,11 +389,15 @@ class FileSystem(object):
def expand(self, path): def expand(self, path):
return os.path.expanduser(os.path.expandvars(path)) return os.path.expanduser(os.path.expandvars(path))
def thumbnail(self, path, width=100, height=100): def thumbnail(self, path, width=100, height=100, sharpen=True):
path = self.expand(path) path = self.expand(path)
if HAVE_PIL: if HAVE_PIL:
output = StringIO() output = StringIO()
Image.open(path).thumbnail((width, height)).save(output, "png") img = Image.open(path)
img.thumbnail((width, height))
if sharpen:
im.filter(ImageFilter.SHARPEN)
img.save(output, "JPEG")
contents = output.getvalue() contents = output.getvalue()
output.close() output.close()
return contents return contents
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment