Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/mrgnw/scripts.
Something went wrong. Try again.
scripts heics
1.2 kB · 49 lines
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950#!/usr/bin/env zshset -euo pipefailsetopt localoptions nocaseglob
extensions=(${(f)"$(globs images -x heic heif)"})files=()for ext in "${extensions[@]}"; do files+=(${~ext}(N))doneif [[ ${#files[@]} -eq 0 ]]; then echo "No image files found." >&2 exit 1fi
orig_size=0for f in "${files[@]}"; do orig_size=$(( orig_size + $(stat -f%z "$f") ))done
mkdir -p originalprintf '%s\0' "${files[@]}" | parallel -0 ' heic_file="{.}.heic" heic {} if [[ -f "$heic_file" ]]; then touch -r {} "$heic_file" fi mv {} original/'
heic_size=0converted=0for f in "${files[@]}"; do heic="${f%.*}.heic" if [[ -f "$heic" ]]; then heic_size=$(( heic_size + $(stat -f%z "$heic") )) (( converted++ )) fidonesaved=$(( orig_size - heic_size ))if (( orig_size > 0 )); then pct=$(( saved * 100 / orig_size )) if (( orig_size > 1048576 )); then printf '%d files: %.1fMB → %.1fMB (saved %.1fMB, %d%%)\n' \ $converted $(( orig_size / 1048576.0 )) $(( heic_size / 1048576.0 )) $(( saved / 1048576.0 )) $pct else printf '%d files: %dKB → %dKB (saved %dKB, %d%%)\n' \ $converted $(( orig_size / 1024 )) $(( heic_size / 1024 )) $(( saved / 1024 )) $pct fifi