Skip to content

Instantly share code, notes, and snippets.

@sabas
Created December 13, 2014 16:09
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 sabas/880da3d5656c4ee52edb to your computer and use it in GitHub Desktop.
Save sabas/880da3d5656c4ee52edb to your computer and use it in GitHub Desktop.
Resize photos (found online)
#!/bin/bash
for file in ./*
do
# next line checks the mime-type of the file
IMAGE_TYPE=`file --mime-type -b "$file" | awk -F'/' '{print $1}'`
if [ "x$IMAGE_TYPE" == "ximage" ]; then
WIDTH=`imageinfo --width "$file"` # obtaining the image width
HEIGHT=`imageinfo --height "$file"` # obtaining the image height
# If the image width is greater that 200 or the height is greater that 150 a thumb is created
if [ $WIDTH -ge 201 ] || [ $HEIGHT -ge 151 ]; then
#This line convert the image in a 200 x 150 thumb
convert -sample 75x50 "$file" "$(dirname "$file")/thumb_$(basename "$file")"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment