-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanga-resizer.sh
executable file
·50 lines (40 loc) · 1.41 KB
/
manga-resizer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# This script takes a .cbz file, and runs an ImageMagick command
# to resize each image with a high quality filter (Lanczos) to the
# resolution of your reading device. It will create an output .cbz
# in your current directory.
# Note: Need to have ImageMagick installed and in PATH. The `unzip`
# and `zip` commands likely only work on macOS, but modifying for
# other OS's should be straight forward.
# Change this to your device's resolution
resolution="1640x2360"
if [[ ! -f $1 ]] || [[ $1 != *.cbz ]]; then
echo "Not a valid .cbz"
exit 1
fi
cbzFile="$1"
cbzBase="$(basename "$1" .cbz)"
# Unzip the original
echo "Unzipping '${cbzFile}'"
extractedDir="/tmp/${cbzBase}"
unzip -d "$extractedDir" "$cbzFile" >/dev/null
# Resize all original images
resizedDir="$extractedDir - Resized"
mkdir "$resizedDir"
images="$(find "$extractedDir" -type f \( -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" \))"
total=$(echo "$images" | wc -l | xargs)
count=1
echo "$images" | while read -r image; do
echo -ne "Resizing image ${count}/${total}\r"
magick "$image" -resize "$resolution" -filter Lanczos -quality 100 "$resizedDir/$(basename "$image")"
((count = count + 1))
done
echo
# Delete the unzipped original
rm -rf "$extractedDir"
# Create new .cbz
newCbz="./${cbzBase} - Resized.cbz"
zip -rj -0 "$newCbz" "$resizedDir" >/dev/null
echo -e "Created new .cbz at '${newCbz}'!\n"
# Delete resized images
rm -rf "$resizedDir"