Last active
October 19, 2021 04:07
-
-
Save brunomarks7/3de90675b29ca0079f064f1f1ebd45e1 to your computer and use it in GitHub Desktop.
CWEBP - Convert all png images to webp recursively
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| curl -O https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-0.4.1-linux-x86-64.tar.gz | |
| mkdir cwebp_folder && tar xf libwebp-0.4.1-linux-x86-64.tar.gz -C cwebp_folder --strip-components 1 | |
| cp ./cwebp_folder/bin/cwebp ./ | |
| find . -name '*.png' -type f -exec bash -c './cwebp -q 90 "$0" -o "${0%.png}.webp"' {} \; | |
| rm *.gz cwebp && rm -rf cwebp_folder |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM nginx | |
| LABEL maintainer="[email protected]" | |
| COPY /images /usr/share/nginx/html | |
| RUN apt update && apt install -y curl | |
| RUN curl -O https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-0.4.1-linux-x86-64.tar.gz | |
| RUN mkdir cwebp_folder && tar xf libwebp-0.4.1-linux-x86-64.tar.gz -C cwebp_folder --strip-components 1 | |
| RUN cp ./cwebp_folder/bin/cwebp ./ | |
| RUN find . -name '*.png' -type f -exec bash -c './cwebp -q 90 "$0" -o "${0%.png}.webp"' {} \; | |
| RUN cd /usr/share/nginx/html && find . -type f -name "*.html" -print0 | xargs -0 sed -i 's/.png/.webp/g' | |
| RUN rm *.gz cwebp && \ | |
| rm -rf cwebp_folder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment