Last active
August 29, 2015 14:01
-
-
Save show0k/2849088b33aaf8fe36d1 to your computer and use it in GitHub Desktop.
Convertir en pgm, redimenssioner et rennomer un lot d'images venant du web (téléchargés sur google image avec l'extension de firefox DownloadThemAll) pour l'exploiter dans un algo de traitement d'image
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/bash | |
# | |
# Usage : bash script.sh directory_of_my_pictures | |
# | |
dir=$1 | |
# Need to make a function to allow "cd" | |
myfunction() { | |
cd $dir | |
ls | |
# Convert all pictures in pgm | |
mogrify -format pgm *.png | |
mogrify -format pgm *.PNG | |
mogrify -format pgm *.JPG | |
mogrify -format pgm *.JPEG | |
mogrify -format pgm *.jpeg | |
mogrify -format pgm *.jpg | |
mogrify -format pgm *.gif | |
mogrify -format pgm *.GIF | |
mogrify -format pgm *.bmp | |
mogrify -format pgm *.BMP | |
# Delete old pictures | |
rm *.png | |
rm *.PNG | |
rm *.JPG | |
rm *.JPEG | |
rm *.jpeg | |
rm *.jpg | |
rm *.html | |
rm *.gif | |
rm *.GIF | |
rm *.bmp | |
rm *.BMP | |
#rezise it to avoid too big pictures | |
mogrify -resize 640x480 *pgm | |
# Rename all the pictures with the directory name | |
i=1 | |
for f in $(ls -r *.pgm); do | |
mv "$f" "${dir}_$(printf %04d $i)".pgm ; | |
(( i++ )) | |
done | |
} | |
myfunction | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment