Skip to content

Instantly share code, notes, and snippets.

@Alexhuszagh
Last active June 13, 2021 06:39
Show Gist options
  • Save Alexhuszagh/33ed30b991b77c0e9a3c84e1ad87b36c to your computer and use it in GitHub Desktop.
Save Alexhuszagh/33ed30b991b77c0e9a3c84e1ad87b36c to your computer and use it in GitHub Desktop.
Convert jp2.zip archives to CBZ archives.
#!/bin/bash
# Convert an achive of zipped JP2 files to a CBZ archive.
# Must have ImageMagick with the JP2 extensions enabled.
set -ex
# Get our arguments, and unzip the file.
input="$1"
input_dir=$(dirname "$input")
input_basename=$(basename "$input")
cd "$input_dir"
unzip "$input_basename" -d "$input_basename".tmp
cd "$input_basename".tmp
# Convert all files to jgg.
for file in */*.jp2; do
jpg="${file%.jp2}.jpg"
convert "$file" "$jpg"
rm "$file"
done
# Zip all the subdirectories.
for dir in *; do
zip -qr "$dir".zip "$dir"
mv "$dir".zip "$dir".cbz
done
# Move all the cbz files upwards and remove the tmp directory.
cd ..
for cbz in "$input_basename".tmp/*.cbz; do
basename=$(basename "$cbz")
mv "$cbz" "$basename"
done
rm -r "$input_basename".tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment