Last active
March 28, 2017 15:12
-
-
Save ccat3z/8969b052c514cff44b4b87d6566eb28c to your computer and use it in GitHub Desktop.
各种报名照片转换
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/sh | |
if [ -d out_small_data ];then | |
echo "out_small_data dir existed." | |
read -n 1 -p "remove it?[y/N]" answer | |
echo | |
if [ "$answer" == "y" ];then | |
rm -rf out_small_data | |
else | |
exit | |
fi | |
fi | |
cp data out_small_data -r | |
cd out_small_data | |
FILE_SIZE=300k | |
QUALITY=50 | |
SIZE=100 | |
while [ "$(find ./ -regex '.*\(jpg\|JPG\|png\|jpeg\)' -size +$FILE_SIZE | sed "s/^\.\///")x" != "x" ] | |
do | |
for f in $(find ./ -regex '.*\(jpg\|JPG\|png\|jpeg\)' -size +$FILE_SIZE | sed "s/^\.\///") | |
do | |
#echo "converting $f with $QUALITY% quality..." | |
echo "converting $f with $SIZE% size..." | |
mv $f "tmp$f" | |
convert -quality ${QUALITY} "tmp$f" "tmp2$f" | |
convert -resize $SIZE%x$SIZE% "tmp2$f" $f | |
rm "tmp$f" "tmp2$f" | |
done | |
QUALITY=$(($QUALITY - 1)) | |
SIZE=$(($SIZE - 1)) | |
done | |
for f in $(find ./ -regex '.*\(.png\|.PNG\)$' | sed "s/^\.\///") | |
do | |
echo "convert png file "$f" to jpg file" | |
mv $f "tmp$f" | |
convert "tmp$f" $(echo $f | sed 's/\..*$/.jpg/') | |
rm "tmp$f" | |
done | |
echo "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment