-
Notifications
You must be signed in to change notification settings - Fork 0
/
imagetools.py
executable file
·72 lines (66 loc) · 3.72 KB
/
imagetools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import argparse
from controllers import (
write_gps_info_to_img_file,
write_gps_info_to_img_file_by_kml,
get_gps_from_image_file,
get_create_time_from_image_file,
)
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='imagetools')
parser.add_argument('--foo', action='store_true', help='foo help')
subparsers = parser.add_subparsers(help='sub-command help')
# ------- SUB COMMAND for Write GPS information to image file. -----------------------------------------------------
parser_wgpsimg = subparsers.add_parser('write_gps', help='Write GPS information to image file.',
usage='%(prog)s xxx.jpeg [options]')
parser_wgpsimg.add_argument('image',
help='A image file, such as my_photo.jpg')
parser_wgpsimg.add_argument('-la', '--latitude',
type=float,
metavar='',
required=True,
help='Decimal degrees latitude, such as: 22.578829')
parser_wgpsimg.add_argument('-lo', '--longitude',
type=float,
metavar='',
required=True,
help='Decimal degrees longitude, such as: 114.219687')
parser_wgpsimg.add_argument('-w2g', '--wgs84-to-gcj02',
action='store_true',
help='Whether convert the GPS info from WGS84 to GCJ02')
parser_wgpsimg.add_argument('-g2w', '--gcj02-to-wgs84',
action='store_true',
help='Whether convert the GPS info from GCJ02 to WGS84')
parser_wgpsimg.set_defaults(func=write_gps_info_to_img_file)
# ------- SUB COMMAND for Write GPS information to image file by KML file. -----------------------------------------
parser_gpxw2g = subparsers.add_parser('write_kml', help='Write GPS information to image file by kml file.')
parser_gpxw2g.add_argument('image',
help='A image file, such as my_photo.jpg')
parser_gpxw2g.add_argument('-k', '--kml',
metavar='',
required=True,
help='A kml file, like my_travel.kml')
parser_gpxw2g.set_defaults(func=write_gps_info_to_img_file_by_kml)
# ------- Get GSP info from image file -----------------------------------------------------------------------------
parser_ggps = subparsers.add_parser('get_gps', help='Get GSP info from image file')
parser_ggps.add_argument('image',
help='A image file, such as my_photo.jpg')
parser_ggps.add_argument('-o', '--output',
type=str,
metavar='',
required=False,
help='Output format. One of: (google)')
parser_ggps.set_defaults(func=get_gps_from_image_file)
# ------- Get Create Time info from image file ---------------------------------------------------------------------
parser_gct = subparsers.add_parser('get_ct', help='Get Create Time from image file')
parser_gct.add_argument('image', help='A image file, such as my_photo.jpg')
parser_gct.add_argument('-o', '--output',
type=str,
metavar='',
required=False,
help='Output format, defaut is EXIF.')
parser_gct.set_defaults(func=get_create_time_from_image_file)
args = parser.parse_args()
if hasattr(args, 'func'):
args.func(args)
else:
parser.print_help()