Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "docs/_themes"]
path = docs/_themes
url = git@github.com:mitsuhiko/flask-sphinx-themes.git
url = https://github.com/pallets/flask-sphinx-themes.git
8 changes: 8 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

3.0.4
-----
- Fix comparison between offset-aware and naive datetimes

3.0.3
-----
- Fix compatibility with itsdangerous 2.0+

3.0.2
-----
- Fix a couple Python3 dict API changes.
Expand Down
19 changes: 11 additions & 8 deletions flask_images/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
from PIL import Image, ImageFilter
from flask import request, current_app, send_file, abort

from hmac import compare_digest as constant_time_compare

try:
from itsdangerous import Signer, constant_time_compare
from itsdangerous import Signer
except ImportError:
from itsdangerous import Signer
from itsdangerous._compat import constant_time_compare

from . import modes
from .size import ImageSize
Expand Down Expand Up @@ -255,13 +256,13 @@ def resize(self, image, background=None, **kw):

# Handle the easy cases.
if size.mode in (modes.RESHAPE, None) or size.req_width is None or size.req_height is None:
return image.resize((size.width, size.height), Image.ANTIALIAS)
return image.resize((size.width, size.height), Image.LANCZOS)

if size.mode not in (modes.FIT, modes.PAD, modes.CROP):
raise ValueError('unknown mode %r' % size.mode)

if image.size != (size.op_width, size.op_height):
image = image.resize((size.op_width, size.op_height), Image.ANTIALIAS)
image = image.resize((size.op_width, size.op_height), Image.LANCZOS)

if size.mode == modes.FIT:
return image
Expand Down Expand Up @@ -350,11 +351,13 @@ def handle_request(self, path):
abort(404) # Not found.

raw_mtime = os.path.getmtime(path)
mtime = datetime.datetime.utcfromtimestamp(raw_mtime).replace(microsecond=0)
# log.debug('last_modified: %r' % mtime)
# log.debug('if_modified_since: %r' % request.if_modified_since)
if request.if_modified_since and request.if_modified_since >= mtime:
return '', 304
if request.if_modified_since:
tzinfo = request.if_modified_since.tzinfo
mtime = datetime.datetime.fromtimestamp(raw_mtime, tz=tzinfo).replace(microsecond=0)
if request.if_modified_since >= mtime:
return '', 304

mode = query.get('mode')

Expand Down Expand Up @@ -428,7 +431,7 @@ def handle_request(self, path):
image.save(cache_file, format, quality=quality)
cache_file.close()

return send_file(cache_path, mimetype=mimetype, cache_timeout=cache_timeout)
return send_file(cache_path, mimetype=mimetype, max_age=cache_timeout)



Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(

name='Flask-Images',
version='3.0.2',
version='3.0.5',
description='Dynamic image resizing for Flask.',
url='http://github.com/mikeboers/Flask-Images',

Expand Down