scripts/cbz2ebook.sh

38 lines
880 B
Bash
Raw Normal View History

#!/usr/bin/env zsh -i
2020-01-16 19:25:19 +01:00
set -e
size="1440x1920" # Kobo Forma
#size="768x1024" # Amazon Kindle Paperwhite
vertical_size="$(cut -dx -f2 <<< $size)x$(cut -dx -f1 <<< $size)"
2020-01-16 19:25:19 +01:00
infile="$(realpath $1)"
outfile="$(realpath $2)"
tmpdir=$(mktemp -d)
function cleanup {
rm -rf "$tmpdir"
}
trap cleanup EXIT INT SIGTERM
cd "$tmpdir"
unzip "$infile"
renumber 4 **/*.???
length=$(ls -1 **/*.??? | wc -l)
2020-01-16 19:25:19 +01:00
position=0
for image in **/*.???; do
2020-01-16 19:25:19 +01:00
width=$(identify -format "%W" "$image")
height=$(identify -format "%H" "$image")
if (($width > $height)); then
mogrify -resize "$vertical_size" -rotate 270 "$image"
2020-01-16 19:25:19 +01:00
else
mogrify -resize "$size" "$image"
2020-01-16 19:25:19 +01:00
fi
position=$(($position + 1))
echo -ne "$(printf '%3s' $((100 * $position / $length))) % "$(printf "%0*d" "$((72 * $position / $length))" 0 | tr '0' '#')'\r'
done
echo
zip "$outfile" **/*.???
2020-01-16 19:25:19 +01:00
cd -