Created
November 15, 2025 22:16
-
-
Save elfsternberg/aab94aa0155234409a94d1f10b0790de to your computer and use it in GitHub Desktop.
webcam-compress: Monitor a folder and as the webcam dumps JPGs into it, convert them to WEBP
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
| #!/usr/bin/env bash | |
| # A very simple script to watch a folder for new images. When new images | |
| # are written to the folder, automatically convert them to webp and, if the | |
| # conversion is successful, delete the JPG. | |
| # Require ImageMagick and inotify-tools | |
| set -o errexit | |
| set -o nounset | |
| shopt -s nullglob | |
| inotifywait -m -e close_write --include '\.jpg$' . | | |
| while read -r _path _action file; do | |
| if [[ "$file" == *".jpg" ]]; then | |
| sleep 1 | |
| for jpg in *.jpg ; do | |
| convert "$jpg" $(echo "$jpg" | sed 's/\.jpg$/.webp/') && rm "$jpg" | |
| echo "Converted $jpg to webp format." | |
| done | |
| fi | |
| done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment