Last active
November 14, 2017 14:20
-
-
Save unot/4650745 to your computer and use it in GitHub Desktop.
Zipped jpeg files to CBZ file for Kobo Glo.
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 -ex | |
# zip2cbz.sh | |
# Written by Takashi UNO | |
# require: zip, ImageMagick | |
if [ $# -ne 1 ]; then | |
echo "USAGE: `basename $0` hogehoge.zip" | |
exit 1 | |
fi | |
for cmd in zip unzip convert ; do | |
if [ ! -x "`which $cmd`" ]; then | |
echo "command $cmd is not found." | |
exit 1 | |
fi | |
done | |
if [ ! -f "$1" ]; then | |
echo "$1: file not exist." | |
exit 1 | |
fi | |
TMPDIR="/var/tmp/`basename "$1" .zip`" | |
# TMPDIR="${1%.zip}" | |
trap 'rm -rf "${TMPDIR}"' EXIT | |
mkdir -p "${TMPDIR}/unzip" | |
mkdir "${TMPDIR}/png" | |
unzip -jq "$1" -d "${TMPDIR}/unzip" | |
OPTIPNGOPTIONS="-quiet" | |
SIZE="758x1024" | |
pushd "${TMPDIR}/unzip" >/dev/null | |
if [ ! -x `which parallel` ]; then | |
for src in *.jpg ; do | |
convert "$src" \ | |
-type grayscale \ | |
# -sharpen 5 \ | |
-fuzz 50% -trim \ | |
-linear-stretch 2%x2% \ | |
-bordercolor white -border 2%x2% \ | |
png:- | convert - -depth 4 -resize ${SIZE} ../png/"${src%.jpg}.png" | |
test -x `which optipng` && optipng ${OPTIPNGOPTIONS} ../png/"${src%.jpg}.png" | |
done | |
else | |
ls *.jpg | parallel -j4 "convert {} \ | |
-type grayscale \ | |
-fuzz 50% -trim \ | |
-linear-stretch 2%x2% \ | |
-bordercolor white -border 2%x2% \ | |
png:- | convert - -depth 4 -resize $SIZE ../png/{.}.png" | |
test -x `which optipng` && optipng ${OPTIPNGOPTIONS} ../png/*.png | |
fi | |
popd >/dev/null | |
zip -jqr "${1%.zip}.cbz" "${TMPDIR}/png" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment