您可以通过以下方法按地理位置和日期重命名文件夹中的所有 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
或者甚至更好,是否可以获取并添加地理位置的城市并将其添加到名称中?
答案1
这将产生一个较短的版本:
exiftool -coordFormat '%.4f' '-filename<${gpslatitude;} ${gpslongitude} ${datetimeoriginal}_$filename' -d "%Y-%m-%d_%H.%M.%S%%-c.%%e" *.JPG
但它仍然添加罗盘点 N、E、S 或 W
如果您想添加城市,可以使用循环添加提名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