36 lines
780 B
Bash
Executable File
36 lines
780 B
Bash
Executable File
#!/bin/zsh -i
|
|
set -e
|
|
|
|
SIZE="1440x1920" # Kobo Forma
|
|
#SIZE="768x1024" # Amazon Kindle Paperwhite
|
|
|
|
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)
|
|
position=0
|
|
for image in **/*; do
|
|
width=$(identify -format "%W" "$image")
|
|
height=$(identify -format "%H" "$image")
|
|
if (($width > $height)); then
|
|
mogrify -resize "$SIZE" -rotate 270 "$image"
|
|
else
|
|
mogrify -resize "$SIZE" "$image"
|
|
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" **/*
|
|
cd -
|