Skip to content

Instantly share code, notes, and snippets.

@mrdwab
Last active November 22, 2018 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrdwab/ff135690bc4e20c573ec76aac9440764 to your computer and use it in GitHub Desktop.
Save mrdwab/ff135690bc4e20c573ec76aac9440764 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Reduces the size of oversized jpegs, optimizes them, and compresses them to a cbz format
# Set the output file based on the input directory
filename=$(basename "$PWD").cbz
# Resize the jpegs to 50% of their original dimensions.
# NOTE: THIS OVERWRITES THE EXISTING FILES!
echo '>>>>> RESIZING JPEGS >>>>>'
mogrify -monitor -resize 50% *.jpeg
# Optimize the resized images
# NOTE: THIS OVERWRITES THE EXISTING FILES!
echo '>>>>> OPTIMIZING JPEGS >>>>>'
jpegoptim -m 75 *.jpeg
# Gather the names of all the jpegs into a list and zip it
echo '>>>>> CREATING ZIP >>>>>'
ls *.jpeg > zip.lst
cat zip.lst | zip -@ "$filename"
# Remove all files except for the cbz
rm zip.lst
rm *.jpeg
echo '>>>>> FILE CREATED >>>>>'
#!/bin/bash
# Converts limited color jpgs to pngs and compresses them to a cbz format
# Set the output file name based on the input directory
filename=$(basename "$PWD").cbz
# Convert all jpgs to pngs, limiting to 16 colors
for img in $(find . -iname '*.jpg'); do echo -n "Converting $img"; convert "$img" -colors 16 "${img%.*}.png" && echo ' [Done]'; done
# Remove the jpgs
echo '>>>>> REMOVING JPGs >>>>>'
rm *.jpg
# Compress the pngs
echo '>>>>> COMPRESSING PNGS >>>>>'
crunch *.png
# crunch creates files with original_file_nme-crunch.png
# Group these into a list of files to zip
ls *-crunch* > zip.lst
cat zip.lst | zip -@ "$filename"
# Remove all files except for the cbz
rm zip.lst
rm *.png
echo '>>>>> FILE CREATED >>>>>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment