From 1aa4c9b69ddcbceaed70407524abe9d82deddcfd Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 17 Aug 2025 11:07:51 -0400 Subject: Update optimize-image script and convert overview to webp --- README.md | 2 +- executables/bin/optimize-image | 74 +++++++++++++++++++++++++++++++++++++---- screenshots/overview.png | Bin 1971364 -> 0 bytes screenshots/overview.webp | Bin 0 -> 428956 bytes 4 files changed, 69 insertions(+), 7 deletions(-) delete mode 100644 screenshots/overview.png create mode 100644 screenshots/overview.webp diff --git a/README.md b/README.md index f1976c3..85ffe09 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Configuration files and scripts for my macOS development environment. -![Screenshot of Development Environment](./screenshots/overview.png) +![Screenshot of Development Environment](./screenshots/overview.webp) ## What's Included diff --git a/executables/bin/optimize-image b/executables/bin/optimize-image index c3de480..0f67408 100755 --- a/executables/bin/optimize-image +++ b/executables/bin/optimize-image @@ -1,21 +1,83 @@ #!/bin/sh +set -e + +quality=85 +source_img_path="" +result_img_path="" main() { - source_img_path="$1" + parse_args "$@" + + original_size=$(get_file_size "$source_img_path") + echo "Optimizing: $source_img_path -> $result_img_path (quality: $quality%)" + magick "$source_img_path" -strip -quality 85% "$result_img_path" + new_size=$(get_file_size "$result_img_path") + echo "File size: $original_size -> $new_size" +} + +parse_args() { + while [ $# -gt 0 ]; do + case $1 in + --quality) + if [ -n "$2" ] && [ "$2" -ge 1 ] && [ "$2" -le 100 ] 2>/dev/null; then + quality="$2" + shift 2 + else + echo "Error: --quality requires a number between 1 and 100" + exit 1 + fi + ;; + -h | --help) + print_usage + exit 0 + ;; + -*) + echo "Error: Unknown option $1" + print_usage + exit 1 + ;; + *) + if [ -z "$source_img_path" ]; then + source_img_path="$1" + else + echo "Error: Too many arguments" + print_usage + exit 1 + fi + shift + ;; + esac + done + if [ -z "$source_img_path" ]; then + echo "Error: source image path is required" print_usage exit 1 fi - result_img_path="$2" - if [ -z "$result_img_path" ]; then - result_img_path="$source_img_path" + + if [ ! -f "$source_img_path" ]; then + echo "Error: Source file '$source_img_path' does not exist" + exit 1 fi - magick "$source_img_path" -strip -interlace Plane -gaussian-blur 0.05 -quality 85% "$result_img_path" + result_img_path="${source_img_path%.*}.webp" } print_usage() { - echo "Usage: $0 [result-img-path]" + echo "Usage: $0 [OPTIONS] " + echo "" + echo "Options:" + echo " --quality Set quality (1-100, default: 85)" + echo " -h, --help Show this help message" + echo "" + echo "Examples:" + echo " $0 input.jpg" + echo " $0 --quality 90 input.jpg" + echo " $0 --quality 80 input.png" +} + +get_file_size() { + du -h "$1" | awk '{ print $1 }' } main "$@" diff --git a/screenshots/overview.png b/screenshots/overview.png deleted file mode 100644 index bb3ddfa..0000000 Binary files a/screenshots/overview.png and /dev/null differ diff --git a/screenshots/overview.webp b/screenshots/overview.webp new file mode 100644 index 0000000..ece0a37 Binary files /dev/null and b/screenshots/overview.webp differ -- cgit v1.2.3