Created
November 20, 2018 10:52
-
-
Save watanabeyu/4066ec36236b3d2b672841bc2fbdb714 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
max=3000000 | |
maxWidth=2000 | |
maxHeight=1000 | |
for file in `\find ./docs -maxdepth 2 -name '*.png'`; do | |
hoge=$(identify -format "%w %h" $file) | |
IFS=' ' | |
set -- $hoge | |
imageSize=$(($1*$2)) | |
newFile=${file%.*}".jpg" | |
if [ $imageSize -gt $max ]; then | |
diff=$(($imageSize-$max)) | |
if [ $1 -gt $2 ]; then | |
#横の方が大きい | |
convert $file -resize ${maxwidth}x -quality 100 $newFile | |
else | |
#縦の方が大きい | |
convert $file -resize x${maxHeight} -quality 100 $newFile | |
fi | |
else | |
convert $file -quality 100 $newFile | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment