def receipt_rotate(receipt_uid, direction): img = ReceiptImage.get(receipt_uid) imgPath = os.path.join(RECEIPT_IMAGE_FOLDER, img.contentPath) angle = -90 if direction == 'right' else 90 #rotated = None with open(imgPath, 'r') as f: im = Image.open(f) rotated = im.rotate(angle) for x in glob.glob('%s.*' % (imgPath, )): os.unlink(x) rotated.save(imgPath) return ''
def receipt_thumb(receipt_uid, size): img = ReceiptImage.get(receipt_uid) imgPath = os.path.join(RECEIPT_IMAGE_FOLDER, img.contentPath) if size != 'thumb': return Response(file(imgPath, 'r'), direct_passthrough=True) thumbSize = 100 thumbPath = '%s.%s-thumb' % (imgPath, thumbSize) if not os.path.exists(thumbPath): im = Image.open(imgPath) im.thumbnail((thumbSize, thumbSize), Image.ANTIALIAS) im.save(thumbPath, "JPEG") r = Response(file(thumbPath, 'r'), mimetype="image/jpeg", direct_passthrough=True) #r.cache_control.max_age = 60*60*24 #import datetime #r.expires = datetime.datetime(2014,1,1) return r