Created
January 26, 2024 03:43
-
-
Save joshuaboud/f39d901d3bf0cebdb112ce6d10d08ec2 to your computer and use it in GitHub Desktop.
Normalize images in CBZ file for e-Reader. Fixes contrast issues for manga.
This file contains 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 | |
# usage: | |
# batch-fix-cbz.sh comic1.cbz [comic2.cbz ...] | |
# WARNING: overwrites original file | |
die() { | |
EXIT_CODE=$? | |
echo "$*" >&2 | |
exit $EXIT_CODE | |
} | |
for cbz in "$@"; do | |
echo "Normalizing $cbz..." | |
test -f "$cbz" || die "Not a file: $cbz" | |
cbz_dir=$(mktemp -d) || die "Failed to make temp dir" | |
unzip -q "$cbz" -d "$cbz_dir" || die "Failed to unzip archive" | |
find "$cbz_dir" -type f \( -iname '*.jpg' -o -iname '*.png' \) -print0 | xargs --null -r -P "$(("$(nproc)"*3/2))" \ | |
mogrify -level 5%,95% -contrast-stretch 10%,15% || die "Failed to equalize images" | |
cp -a "$cbz" "$cbz.old" || die "Failed to backup original CBZ" | |
zip -q -j -r "$cbz" "$cbz_dir" || die "Failed to replace original CBZ" | |
echo "Done" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment