Exif使用
使用 exivtool
按位置重命名照片
這是您可以按地理位置和日期重命名文件夾中所有 Jpeg 的方法:
exiftool '-filename<${gpslatitude;} ${gpslongitude} ${datetimeoriginal}' -d "%Y-%m-%d %H.%M.%S%%-c.%%e" *.JPG
這會導致非常長的文件名,例如
53 33 36.95000000 N 9 58 29.37000000 E 2015-11-04 19.22.49.JPG
我怎樣才能使用短位置呢?所以它會導致
53.560308 9.975458 2015-11-04 19.22.49.JPG
或者更好的是,是否可以獲取並添加地理位置所在的城市並將其添加到名稱中?
這將導致更短的版本:
exiftool -coordFormat '%.4f' '-filename<${gpslatitude;} ${gpslongitude} ${datetimeoriginal}_$filename' -d "%Y-%m-%d_%H.%M.%S%%-c.%%e" *.JPG
但它仍然添加了羅盤點 N、E、S 或 W
如果要添加城市,可以使用nominatim API循環添加:
#!/bin/bash #exiftool '-filename<${datetimeoriginal}_$filename' -d "%Y-%m-%d_%H.%M.%S%%-c.%%e" *.JPG for f in *.JPG; do echo "$f" LAT="$(exiftool -coordFormat '%.4f' "$f"|egrep 'Latitude\s+:'|cut -d\ -f 23)" if [ "$LAT" == "" ]; then echo 'no geo coordinates'; else LON="$(exiftool -coordFormat '%.4f' "$f"|egrep 'Longitude\s+:'|cut -d\ -f 22)" URL='http://nominatim.openstreetmap.org/reverse?format=xml&lat='$LAT'&lon='$LON'&zoom=18&addressdetails=1' RES="$(curl -s "$URL"|egrep "<(city|village|town|ruins|state_district|country)")" LOC="$(echo "$RES"|grep '<city>'|sed 's/^.*<city>//g'|sed 's/<\/city>.*$//g')" if [ "$LOC" == "" ]; then LOC="$(echo "$RES"|grep '<city_district>'|sed 's/^.*<city_district>//g'|sed 's/<\/city_district>.*$//g')" fi if [ "$LOC" == "" ]; then LOC="$(echo "$RES"|grep '<village>'|sed 's/^.*<village>//g'|sed 's/<\/village>.*$//g')" fi if [ "$LOC" == "" ]; then LOC="$(echo "$RES"|grep '<town>'|sed 's/^.*<town>//g'|sed 's/<\/town>.*$//g')" fi if [ "$LOC" == "" ]; then LOC="$(echo "$RES"|grep '<ruins>'|sed 's/^.*<ruins>//g'|sed 's/<\/ruins>.*$//g')" fi if [ "$LOC" == "" ]; then LOC="$(echo "$RES"|grep '<state_district>'|sed 's/^.*<state_district>//g'|sed 's/<\/state_district>.*$//g')" fi if [ "$LOC" == "" ]; then LOC="$(echo "$RES"|grep '<country>'|sed 's/^.*<country>//g'|sed 's/<\/country>.*$//g')" fi if [ "$LOC" == "" ]; then echo "no city found at $URL"; else BASE="${f%.*}" mv -v "$f" "$BASE-$LOC.JPG" fi fi done
完成後,您可以按位置計算圖像
ls -1|cut -d- -f 4|sort|uniq -c|sort -n