Skip to content

Instantly share code, notes, and snippets.

@watanabeyu
Created November 20, 2018 10:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watanabeyu/4066ec36236b3d2b672841bc2fbdb714 to your computer and use it in GitHub Desktop.
Save watanabeyu/4066ec36236b3d2b672841bc2fbdb714 to your computer and use it in GitHub Desktop.
#!/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