compress logo as jpeg and webp
This commit is contained in:
parent
78d8c89bd9
commit
ae19b326af
32
dodo.py
32
dodo.py
|
@ -3,19 +3,31 @@ def task_gen_logo():
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
def resize_logo(width):
|
def resize_logo(width, format):
|
||||||
with Image.open('assets/logotype.png') as im:
|
with Image.open('assets/logotype.png') as im:
|
||||||
im = im.convert('L')
|
im = im.convert('RGB')
|
||||||
height = im.height * width // im.width
|
height = im.height * width // im.width
|
||||||
new = im.resize((width,height), resample=Image.LANCZOS)
|
new = im.resize((width,height), resample=Image.LANCZOS)
|
||||||
new.save('static/logotype-{}.png'.format(width), optimize=True)
|
if format == 'jpeg':
|
||||||
|
kwargs = dict(
|
||||||
|
optimize = True,
|
||||||
|
progressive = True,
|
||||||
|
quality = 80,
|
||||||
|
)
|
||||||
|
elif format == 'webp':
|
||||||
|
kwargs = dict(
|
||||||
|
quality = 79,
|
||||||
|
)
|
||||||
|
new.save('static/logotype-{}.{}'.format(width, format), **kwargs)
|
||||||
|
|
||||||
widths = (200, 400, 600, 800)
|
widths = (200, 400, 600, 800)
|
||||||
|
formats = ('jpeg', 'webp')
|
||||||
for width in widths:
|
for width in widths:
|
||||||
|
for format in formats:
|
||||||
yield dict(
|
yield dict(
|
||||||
name=str(width),
|
name='{}.{}'.format(width, format),
|
||||||
actions=[(resize_logo, (width,))],
|
actions=[(resize_logo, (width, format))],
|
||||||
targets=[f'static/logotype-{width}.png'],
|
targets=[f'static/logotype-{width}.{format}'],
|
||||||
file_dep=['assets/logotype.png'],
|
file_dep=['assets/logotype.png'],
|
||||||
clean=True,
|
clean=True,
|
||||||
)
|
)
|
||||||
|
@ -50,6 +62,12 @@ def task_minify_css():
|
||||||
clean=True,
|
clean=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def cross(a, b):
|
||||||
|
for A in a:
|
||||||
|
for B in b:
|
||||||
|
yield (A, B)
|
||||||
|
|
||||||
def task_compress_static():
|
def task_compress_static():
|
||||||
import brotli
|
import brotli
|
||||||
import gzip
|
import gzip
|
||||||
|
@ -59,7 +77,7 @@ def task_compress_static():
|
||||||
'static/icon.png',
|
'static/icon.png',
|
||||||
'static/logotype.png',
|
'static/logotype.png',
|
||||||
'static/settings.js',
|
'static/settings.js',
|
||||||
) + tuple((f'static/logotype-{width}.png' for width in (200, 400, 600, 800)))
|
) + tuple((f'static/logotype-{width}.{format}' for width, format in cross((200, 400, 600, 800), ('jpeg','webp'))))
|
||||||
|
|
||||||
def compress_brotli(dependencies):
|
def compress_brotli(dependencies):
|
||||||
for filename in dependencies:
|
for filename in dependencies:
|
||||||
|
|
|
@ -23,11 +23,18 @@
|
||||||
<header>
|
<header>
|
||||||
<h1>
|
<h1>
|
||||||
<a href="{{url_for('index')}}">
|
<a href="{{url_for('index')}}">
|
||||||
<img src="{{ st('logotype-200.png') }}" alt="Forget" width='200px' height='144px' sizes='200px' srcset="
|
<picture>
|
||||||
|
<source type='image/webp' sizes='200px' srcset="
|
||||||
{%- for width in (200,400,600,800) -%}
|
{%- for width in (200,400,600,800) -%}
|
||||||
{{ st('logotype-{}.png'.format(width)) }} {{width}}w,
|
{{ st('logotype-{}.webp'.format(width)) }} {{width}}w,
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
"/>
|
"/>
|
||||||
|
<img src="{{ st('logotype-200.jpeg') }}" alt="Forget" width='200px' height='144px' sizes='200px' srcset="
|
||||||
|
{%- for width in (200,400,600,800) -%}
|
||||||
|
{{ st('logotype-{}.jpeg'.format(width)) }} {{width}}w,
|
||||||
|
{%- endfor -%}
|
||||||
|
"/>
|
||||||
|
</picture>
|
||||||
</a>
|
</a>
|
||||||
</h1>
|
</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
Loading…
Reference in New Issue