Skip to content

Instantly share code, notes, and snippets.

@evmn
Last active October 18, 2021 11:59
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 evmn/da32ee14e787976dc8112e11afe6d0cb to your computer and use it in GitHub Desktop.
Save evmn/da32ee14e787976dc8112e11afe6d0cb to your computer and use it in GitHub Desktop.
Generate thumb for cover.jpg generate by Calibre
#!/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