Skip to content
Merged
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
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
-e .
coverage==4.3.1
django-coverage-plugin==1.3.1
flake8==3.2.1
isort==4.2.5
mccabe==0.5.3
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ match = (?!setup).*.py

[coverage:run]
source = .
plugins =
django_coverage_plugin
omit =
*/migrations/*
*/tests/*
Expand Down
12 changes: 11 additions & 1 deletion stdimage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def render_variation(cls, file_name, variation, replace=False,

with storage.open(file_name) as f:
with Image.open(f) as img:
save_kargs = {}
file_format = img.format

if cls.is_smaller(img, variation):
Expand All @@ -93,6 +94,15 @@ def render_variation(cls, file_name, variation, replace=False,
size = variation['width'], variation['height']
size = tuple(int(i) if i != float('inf') else i
for i in size)

if file_format == 'JPEG':
# http://stackoverflow.com/a/21669827
img = img.convert('RGB')
save_kargs['optimize'] = True
save_kargs['quality'] = 'web_high'
if size[0] * size[1] > 10000: # roughly <10kb
save_kargs['progressive'] = True

if variation['crop']:
img = ImageOps.fit(
img,
Expand All @@ -106,7 +116,7 @@ def render_variation(cls, file_name, variation, replace=False,
)

with BytesIO() as file_buffer:
img.save(file_buffer, file_format)
img.save(file_buffer, file_format, **save_kargs)
f = ContentFile(file_buffer.getvalue())
storage.save(variation_name, f)
return variation_name
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ deps=
dj110: https://github.com/django/django/archive/stable/1.10.x.tar.gz#egg=django
djmaster: https://github.com/django/django/archive/master.tar.gz#egg=django
commands=
py.test \
coverage run --source=stdimage -m 'pytest' \
--basetemp={envtmpdir} \
--ignore=.tox \
{posargs}
coverage report

[testenv:qa]
changedir={toxinidir}
Expand Down