diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b8caf52 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,39 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Documents +*.md text eol=lf +*.tex text diff=tex +*.adoc text +*.textile text +*.mustache text eol=lf +*.csv text +*.tab text +*.tsv text +*.txt text +*.sql text + +# Scripts +*.bash text eol=lf +*.fish text eol=lf +*.sh text eol=lf + +# Source files +# ============ +*.pxd text diff=python +*.py text diff=python +*.py3 text diff=python +*.pyc text diff=python +*.pyd text diff=python +*.pyo text diff=python +*.pyw text diff=python +*.pyx text diff=python +*.pyz text diff=python + + +# +# Exclude files from exporting +# + +.gitattributes export-ignore +.gitignore export-ignore \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 7900a62..8aabbc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,8 @@ script: - sudo apt-get install jpegoptim -y - sudo -E time bash scripts/install-webp.sh > /dev/null 2>&1 - sudo -E time bash scripts/install-optipng.sh > /dev/null 2>&1 + - sudo wget -qO /usr/local/bin/avif https://github.com/Kagami/go-avif/releases/download/v0.1.0/avif-linux-x64 + - sudo chmod +x /usr/local/bin/avif - sudo cp optimize.sh /usr/local/bin/img-optimize - sudo chmod 755 /usr/local/bin/img-optimize - /usr/local/bin/img-optimize --all diff --git a/optimize.sh b/optimize.sh index 69e2a95..3aa1f7e 100755 --- a/optimize.sh +++ b/optimize.sh @@ -7,7 +7,7 @@ # Author: VirtuBox # License: M.I.T # ---------------------------------------------------------------------------- -# Version 1.1 - 2019-09-24 +# Version 1.2 - 2020-10-18 # ---------------------------------------------------------------------------- CSI='\033[' @@ -27,8 +27,9 @@ _help() { echo " --jpg ..... optimize all jpg images" echo " --png ..... optimize all png images" echo " --webp ..... convert all images in webp" + echo " --avif ..... convert all images in avif" echo " --nowebp ..... optimize all png & jpg images" - echo " --all ..... optimize all images (png + jpg + webp)" + echo " --all ..... optimize all images (png + jpg + webp +avif)" echo " -i, --interactive ..... run img-optimize in interactive mode" echo " -q, --quiet ..... run image optimization quietly" echo " --path ..... define images path" @@ -68,10 +69,14 @@ else --webp) WEBP_OPTIMIZATION="y" ;; + --avif) + AVIF_OPTIMIZATION="y" + ;; --all) PNG_OPTIMIZATION="y" JPG_OPTIMIZATION="y" WEBP_OPTIMIZATION="y" + AVIF_OPTIMIZATION="y" ;; -i | --interactive) INTERACTIVE_MODE="1" @@ -143,6 +148,16 @@ if [ "$INTERACTIVE_MODE" = "1" ]; then echo "" echo "" fi + if [ -z "$AVIF_OPTIMIZATION" ]; then + echo "" + echo "Do you want to convert all jpg & png images to WebP in $IMG_PATH ? (y/n)" + while [[ $AVIF_OPTIMIZATION != "y" && $AVIF_OPTIMIZATION != "n" ]]; do + echo "Select an option [y/n]: " + read -r AVIF_OPTIMIZATION + done + echo "" + echo "" + fi fi ################################## @@ -215,6 +230,38 @@ if [ "$WEBP_OPTIMIZATION" = "y" ]; then echo -ne " jpg to webp conversion [${CGREEN}OK${CEND}]\\r" echo -ne '\n' fi +if [ "$AVIF_OPTIMIZATION" = "y" ]; then + [ -z "$(command -v avif)" ] && { + echo "Error: avif isn't installed" + exit 1 + } + # convert png to webp + echo -ne ' png to avif conversion [..]\r' + cd "$IMG_PATH" || exit 1 + if [ -n "$FIND_ARGS" ]; then + find . -type f -iname "*.png" -cmin "$FIND_ARGS" -print0 | xargs -0 -r -I {} \ + bash -c "[ ! -f '{}.avif' ] && { avif -e '{}' -o '{}.avif'; }" + else + find . -type f -iname "*.png" -print0 | xargs -0 -r -I {} \ + bash -c "[ ! -f '{}.avif' ] && { avif -e '{}' -o '{}.avif'; }" + fi + echo -ne " png to avif conversion [${CGREEN}OK${CEND}]\\r" + echo -ne '\n' + + # convert jpg to webp + echo -ne ' jpg to avif conversion [..]\r' + cd "$IMG_PATH" || exit 1 + if [ -n "$FIND_ARGS" ]; then + find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -cmin "$FIND_ARGS" -print0 | xargs -0 -r -I {} \ + bash -c "[ ! -f '{}.avif' ] && { avif -e '{}' -o '{}.avif'; }" + else + find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -print0 | xargs -0 -r -I {} \ + bash -c "[ ! -f '{}.avif' ] && { avif -e '{}' -o '{}.avif'; }" + fi + + echo -ne " jpg to avif conversion [${CGREEN}OK${CEND}]\\r" + echo -ne '\n' +fi # We're done ! echo ""