Last active
October 18, 2021 11:59
-
-
Save evmn/da32ee14e787976dc8112e11afe6d0cb to your computer and use it in GitHub Desktop.
Generate thumb for cover.jpg generate by Calibre
This file contains 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
#!/bin/bash | |
find ./ -type f -name cover.jpg | while read -r cover;do | |
backup=`echo "$cover" | sed -e 's/cover\.jpg$/cover_bak\.jpg/'` | |
thumb=`echo "$cover" | sed -e 's/cover\.jpg$/thumb\.jpg/'` | |
# thumb=$(echo "$cover" | rev | cut -d "/" -f 2- | rev)"/thumb.jpg" | |
echo "$thumb" | |
width=$(identify -format '%w' "$cover") | |
if (( width < 350 ));then | |
cp "$cover" "$thumb" | |
elif (( width >=350 && width < 600 ));then | |
convert -resize 50%x50% "$cover" "$thumb" | |
else | |
convert -thumbnail 300 "$cover" "$thumb" | |
fi | |
folder=`echo "$cover" | sed -e 's/cover\.jpg$//'` | |
mv "$cover" "$backup" | |
mv "$thumb" "$cover" | |
echo "$folder" | |
ls -lh "$folder" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment