Skip to content

Instantly share code, notes, and snippets.

@arpith20
Created October 16, 2017 02:02
Show Gist options
  • Save arpith20/411cb102db77ffb3f122769a73c18831 to your computer and use it in GitHub Desktop.
Save arpith20/411cb102db77ffb3f122769a73c18831 to your computer and use it in GitHub Desktop.
A script to crop a batch of images around a face. This was written to automatically extract and crop faces for use in people's section in IISc CSA's website.
for file in ../*.JPG; do
name=$(basename "$file")
i=0
./facedetect --biggest --center "$file" | while read x y; do
convert "$file" -crop 2521x2801+`expr ${x} - 1261`+`expr ${y} - 1200` "../face/${name%.*}_${i}.${name##*.}"
convert "../face/${name%.*}_${i}.${name##*.}" -resize 135x150 "../face/${name%.*}.${name##*.}"
rm "../face/${name%.*}_${i}.${name##*.}"
mogrify -format png "../face/${name%.*}.${name##*.}"
rm "../face/${name%.*}.${name##*.}"
pngquant "../face/${name%.*}.png" --output "../face/${name%.*}.png" --force
i=$(($i+1))
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment