Browse files

ability to crop pictures with get_thumbnail(... crop=True)

  • Loading branch information...
1 parent 3f1ffd4 commit 89bff3a8b3755b9456e1965069ad151c1c33a759 @peterbe committed Jul 1, 2012
Showing with 7 additions and 6 deletions.
  1. +7 −6 tornado_utils/thumbnailer.py
View
13 tornado_utils/thumbnailer.py
@@ -6,31 +6,32 @@
from .utils import mkdir
-def get_thumbnail(save_path, image_data, (max_width, max_height), quality=85):
+def get_thumbnail(save_path, image_data, (max_width, max_height),
+ quality=85, **kwargs):
if not Image:
raise SystemError("PIL.Image was not imported")
if os.path.isfile(save_path):
image = Image.open(save_path)
- #print "FOUND", save_path
return image.size
directory = os.path.dirname(save_path)
mkdir(directory)
basename = os.path.basename(save_path)
original_save_path = os.path.join(directory, 'original.' + basename)
with open(original_save_path, 'wb') as f:
f.write(image_data)
- #print "WROTE", original_save_path
original_image = Image.open(original_save_path)
- image = scale_and_crop(original_image, (max_width, max_height))
+ image = scale_and_crop(
+ original_image,
+ (max_width, max_height),
+ **kwargs
+ )
format = None
try:
image.save(save_path,
format=format,
quality=quality,
optimize=1)
- #print "SAVED", save_path
-
except IOError:
# Try again, without optimization (PIL can't optimize an image
# larger than ImageFile.MAXBLOCK, which is 64k by default)

0 comments on commit 89bff3a

Please sign in to comment.