Created
February 3, 2025 19:42
-
-
Save bohwaz/b5a3feb62cf253cdd8eae5c2f87c8a1b to your computer and use it in GitHub Desktop.
Convert a PDF file to CBZ (Comic Books)
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
#!/bin/bash | |
which mutool &> /dev/null || (echo "mutool is not installed" && exit 1) | |
which convert &> /dev/null || (echo "imagemagick is not installed" && exit 1) | |
which zip &> /dev/null || (echo "zip is not installed" && exit 1) | |
if [ "$1" = "" ] | |
then | |
echo "Usage: $0 File.pdf" | |
exit | |
fi | |
TEMP=`mktemp -d "${TMPDIR:-/tmp}"/pdf2cbz.XXXX` | |
echo "Extracting images..." | |
mutool convert -F png -O height=1920 -o "${TEMP}/page-%04d.png" "$1" | |
echo "Converting" | |
find "${TEMP}" -type f -name "*.png" -exec echo -n . \; -exec convert -quality 92 -strip "{}" "{}.jpg" \; | |
echo "" | |
echo "Zipping..." | |
zip -q -j "${1%.*}.cbz" "${TEMP}"/*.jpg | |
rm -rf "${TEMP}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment