Skip to content

Instantly share code, notes, and snippets.

@Alexhuszagh
Last active November 26, 2025 02:38
Show Gist options
  • Select an option

  • Save Alexhuszagh/33ed30b991b77c0e9a3c84e1ad87b36c to your computer and use it in GitHub Desktop.

Select an option

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
@elliotchance
Copy link

Worked a treat, thanks!

FYI on macOS:

WARNING: The convert command is deprecated in IMv7, use "magick" instead of "convert" or "magick convert"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment