Last active
April 8, 2019 07:55
-
-
Save Purexo/f0aa7dcb843d768dc4cfcf08c20a7952 to your computer and use it in GitHub Desktop.
a bash script (need imagemagick >6.8.3-10, zip, unzip, unrar) who will convert pictures for pocketbook with an inteligent minimal weight
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# a bash script (need imagemagick >6.8.3-10, zip, unzip, unrar) who will convert pictures for pocketbook with an inteligent minimal weight | |
# create UNARCHIVED folder | |
# create TRANSFORMED folder | |
# create OUTPUT folder | |
# | |
# for archive file | |
# unarchive in new folder in UNARCHIVED with name file - ext | |
# move archive in BACKUP folder | |
# | |
# for file in UNARCHIVED | |
# convert in optimized jpg to TRANSFORMED (respect path with root from UNARCHIVED) | |
# | |
# for folder in TRANSFORMED | |
# zip it in cbz to OUTPUT | |
echo '/!\ Warning !' | |
echo 'This program will crawl your current folder for zip, cbz, rar, cbr files' | |
echo 'Extract them in UNARCHIVED' | |
echo 'Convert to PocketBook format your pictures (758x1024) grayscale jpeg in TRANSFORMED' | |
echo 'Zip it in cbz format in OUTPUT' | |
read -p '[ENTER] to continue [CTRL+C] to cancel' | |
size_x=758 | |
size_y=1024 | |
output_format=jpg | |
mkdir -p UNARCHIVED TRANSFORMED OUTPUT | |
find . -maxdepth 1 -type f -name "*.zip" -o -name "*.cbz" -o -name "*.rar" -o -name "*.cbr" | while read file; do | |
ext="${file##*.}" | |
filename="${file##*/}" | |
case $ext in | |
zip|cbz) | |
unzip "$file" -d "UNARCHIVED/${filename%.*}" | |
;; | |
rar|cbr) | |
unrar "$file" "UNARCHIVED/${filename%.*}" | |
;; | |
esac | |
done | |
cd UNARCHIVED | |
find . -type f | while read file; do | |
trailing_file="${file#*./}" # - ./ useless in start of path | |
new_file="../TRANSFORMED/${trailing_file%.*}.${output_format}" | |
mkdir -p "../TRANSFORMED/${trailing_file%/*}" # création du dossier | |
convert -strip -interlace Plane -grayscale Rec709Luma -resize "${size_x}x${size_y}"^ "$file" "$new_file" | |
done | |
cd ../TRANSFORMED | |
find . -maxdepth 1 -mindepth 1 -type d | while read folder; do | |
archive="../OUTPUT/${folder}.cbz" | |
zip -r "$archive" "$folder" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment