Techno-magis

Suppression de l'orientation EXIF d'une liste d'images avec un script

2014年3月23日(日曜日)

À l'origine, j'avais récupéré une solution pour tourner les images de mon numérique. Tous les logiciels ne supportent pas la rotation EXIF, du coup je préfère dans certains cas tourner l'image et supprimer la rotation EXIF. La solution que j'avais trouvée fonctionnait de façon quelque peu erratique avec des cas où la rotation n'était pas faite pour une raison que je n'ai jamais comprise. J'ai pas mal souffert du script foireux pendant mon voyage au Japon (et j'ai jamais vraiment eu le temps de m'y pencher durant mon expédition).

Après un peu de lecture de doc, de recherches sur internet, j'ai corrigé les problèmes et j'ai au passage fait une présentation un peu plus sympa pour montrer l'avancement de la conversion.

Pour faire simple, le script met les extensions en minuscules, crée un dossier « rotated » et copie les fichiers dedans. Ensuite, il parcourt un par un les fichiers pour effectuer une rotation (si nécessaire).

Le prérequis pour le scripts est d'avoir installé convert et exiv2.

コード:

#! /bin/bash
echo "------------------------------------------------------"
echo "----------- EXIF ORIENTATION REMOVER -----------------"
echo "------------------------------------------------------"
echo
echo " Picture rotation start "
 
# create a new folder
[ -d rotated ] ||mkdir rotated
 
# get the .JPG extensions and rename them in .jpg
#
LISTJPG=`ls -l |grep JPG |tail -n 1|awk {'print $8'}`
 
echo $LISTJPG
 
if [ $LISTJPG ]
then
	echo "------------------------------------------------------"
	echo "Rename .JPG extension in .jpg"
 
	for i in *.JPG
	do
		NEWNAME=`ls |grep "$i"|cut -d "." -f1`
		mv "$i" "$NEWNAME.jpg"
		echo " - changing JPG to jpg for $i"
	done
fi
 
# is there any .jpg to process in this folder ?
#
LISTJPG=`ls -l |grep jpg |tail -n 1 |awk {'print $8'}`
INDEX=1
 
if [ $LISTJPG ]
then
 
	# size of list
	SIZE=`find . -maxdepth 1 -name "*.jpg" -type f | wc -l`
	echo "------------------------------------------------------"
 
	find . -maxdepth 1 -name "*.jpg" -type f | while read -r i
	do
		# delete ./ 
		i=${i:2}
 
		ORIENTATION=`LANG=en exiv2 pr -p t "$i" 2>/dev/null | grep -a "Exif.Image.Orientation" | awk {'print $4 $5'}`
 
		echo " $INDEX / $SIZE : “$i” has orientation “$ORIENTATION”"
 
		if [ "$ORIENTATION" = "left,bottom" ]
		then
			echo "      --> rotation left"
			convert "$i" -rotate -90 rotated/"$i"
			LANG=en exiv2 -M "set Exif.Image.Orientation Short 1" rotated/"$i"
 
		elif [ "$ORIENTATION" = "right,top" ]
		then
			echo "      --> rotation rigth"
			convert "$i" -rotate 90 rotated/"$i"
			LANG=en exiv2 -M "set Exif.Image.Orientation Short 1" rotated/"$i"
 
		else
			echo "      --> no rotation"
			cp "$i" rotated/
		fi
 
		((INDEX++))
	done
fi
echo "------------------------------------------------------"
 
echo
echo "operation completed"
echo

カテゴリ:
Zéflingによって、 2014/03/23 00:45:24
505回を読んだ。1件のコメントが投稿されています。
👍 0 👎 0

全1コメント

Zéflingによって、 2016/07/12 00:04:31
アバター
ウェブマスター

Le script est maintenant disponible ici.

Si personne ne s'en souvient, ça n'est jamais arrivé. La mémoire humaine n'est qu'une donnée. On peut la réécrire. (Lain)

コメントを書き込む