ADD resize to images script, CHANGE quality in images script, FIX image template to always use the optimize images if possible
This commit is contained in:
parent
d409a6ba1e
commit
4da5b6d6fd
2 changed files with 30 additions and 5 deletions
|
@ -1,6 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
PARAMS=('-quality 90')
|
# Libary needed: ImageMagick
|
||||||
|
|
||||||
|
PARAMS=('-quality 60')
|
||||||
|
|
||||||
if [ $# -ne 0 ]; then
|
if [ $# -ne 0 ]; then
|
||||||
PARAMS=$@;
|
PARAMS=$@;
|
||||||
|
@ -12,9 +14,18 @@ shopt -s nullglob nocaseglob extglob
|
||||||
shopt -s globstar
|
shopt -s globstar
|
||||||
|
|
||||||
# Resize
|
# Resize
|
||||||
|
sizes=(320 640 960 1280)
|
||||||
|
for FILE in static/**/*.@(jpg|jpeg|tif|tiff|png|gif); do
|
||||||
|
DIR=$(dirname "$FILE")
|
||||||
|
NAME=$(basename "$FILE" | cut -d. -f1)
|
||||||
|
EXTENSION=$(basename "$FILE" | cut -d. -f2)
|
||||||
|
for size in ${sizes[@]}; do
|
||||||
|
convert "$FILE" -resize ${size}x${size}\> "${DIR}/${NAME}-${size}.${EXTENSION}"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
# Web Optimized Formats
|
# Web Optimized Formats
|
||||||
for FILE in static/**/*.@(jpg|jpeg|tif|tiff|png); do
|
for FILE in static/**/*.@(jpg|jpeg|tif|tiff|png|gif); do
|
||||||
convert $PARAMS "$FILE" "${FILE}".webp;
|
convert $PARAMS "$FILE" "${FILE}".webp;
|
||||||
convert $PARAMS "$FILE" "${FILE}".avif;
|
convert $PARAMS "$FILE" "${FILE}".avif;
|
||||||
done
|
done
|
|
@ -4,18 +4,32 @@ url: string
|
||||||
alt: string
|
alt: string
|
||||||
-->
|
-->
|
||||||
{{ $avatar := "avatar"}}
|
{{ $avatar := "avatar"}}
|
||||||
|
{{ $sizes := slice "320" "640" "960" "1280" }}
|
||||||
|
{{ $ext := path.Ext .url }}
|
||||||
|
{{ $name := path.Base (replace .url $ext "") }}
|
||||||
|
{{ $dir := path.Dir .url }}
|
||||||
|
|
||||||
<picture>
|
<picture>
|
||||||
<source
|
<source
|
||||||
type="image/avif"
|
type="image/avif"
|
||||||
src="{{ .url }}.avif"
|
srcset="
|
||||||
|
{{ range $i, $size := $sizes }}
|
||||||
|
{{ $dir }}/{{ $name }}-{{ $size }}{{ $ext }}.avif {{ $size }}w,
|
||||||
|
{{ end }}
|
||||||
|
{{ .url }}.avif
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
<source
|
<source
|
||||||
type="image/webp"
|
type="image/webp"
|
||||||
src="{{ .url }}.webp"
|
srcset="
|
||||||
|
{{ range $i, $size := $sizes }}
|
||||||
|
{{ $dir }}/{{ $name }}-{{ $size }}{{ $ext }}.webp {{ $size }}w,
|
||||||
|
{{ end }}
|
||||||
|
{{ .url }}.webp
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
<img
|
<img
|
||||||
class="{{if eq .type $avatar}} avatar {{end}}"
|
class="{{if eq .type $avatar}}avatar{{end}}"
|
||||||
alt="{{ .alt }}"
|
alt="{{ .alt }}"
|
||||||
src="{{ .url }}"
|
src="{{ .url }}"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
|
|
Loading…
Reference in a new issue