From db3eba231f2476564043e71e77ccaf5755ef6602 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Tue, 3 Sep 2024 09:19:22 +0300 Subject: [PATCH] added zip_image.sh --- Dockerfile | 10 ++++++++++ zip_image.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 zip_image.sh diff --git a/Dockerfile b/Dockerfile index d1b280c4d..70441893a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,17 @@ COPY package-lock.json* . RUN npm ci FROM node:20-alpine +RUN apk update && apk add --no-cache \ + optipng \ + advancecomp \ + pngcrush \ + jpegoptim \ + libwebp-tools \ + findutils \ + bash + WORKDIR /usr/src/app COPY --from=builder /usr/src/app/ /usr/src/app/ COPY . . +RUN chmod +x zip_image.sh ENTRYPOINT ["npx", "quartz"] \ No newline at end of file diff --git a/zip_image.sh b/zip_image.sh new file mode 100644 index 000000000..d64e3c5e0 --- /dev/null +++ b/zip_image.sh @@ -0,0 +1,34 @@ +#!/bin/bash +file=comp.flag + +if [ -f "$file" ]; then + option="-newer $file" +fi + +find ./images/ -type f -not -path "./images/comp/*" ! -name "*-no-comp.*" $option -iname "*.png" -exec sh -c ' + png_file="${1/\/images\//\/images\/comp\/}" + png_dir="$(dirname "$png_file")" + mkdir -p "$png_dir" + cp "$1" "${png_file}" + optipng -o7 "${png_file}" + advpng -z4 "${png_file}" + pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time -ow "${png_file}" +' _ {} \; + +find ./images/ -type f -not -path "./images/comp/*" ! -name "*-no-comp.*" $option -iregex '.*\.\(jpg\|jpeg\)' -exec sh -c ' + jpg_file="${1/\/images\//\/images\/comp\/}" + jpg_dir="$(dirname "$jpg_file")" + mkdir -p "$jpg_dir" + cp "$1" "${jpg_file}" + jpegoptim --all-progressive "${jpg_file}" +' _ {} \; + +find ./images/comp -type f -iregex '.*\.\(jpg\|jpeg\|png\)' -not -iregex '.*no-comp\.\(jpg\|jpeg\|png\)' $option -exec sh -c ' + webp_file="${1/\/images\/comp\//\/images\/webp\/}" + webp_dir="$(dirname "$webp_file")" + mkdir -p "$webp_dir" + cwebp -mt -af -progress -m 6 -q 75 -pass 10 "$1" -o "${webp_file%.*}.webp" +' _ {} \; + +touch $file +echo "$(date)" > $file \ No newline at end of file