geopic-tag-reader 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ __pycache__
2
+ *.egg-info
3
+ dist/
4
+ env/
5
+ venv
6
+ .cache/
@@ -0,0 +1,38 @@
1
+ variables:
2
+ PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
3
+
4
+ cache:
5
+ paths:
6
+ - .cache/pip
7
+
8
+ before_script:
9
+ - python --version # For debugging
10
+ - apk add --update --no-cache libc-dev libffi-dev gcc
11
+
12
+ test mypy:
13
+ image: python:3.9-alpine
14
+ script:
15
+ - pip install .[dev]
16
+ - mypy geopic_tag_reader/
17
+
18
+ lint:
19
+ image: python:3.9-alpine
20
+ script:
21
+ - pip install .[dev]
22
+ - black --fast --check .
23
+
24
+ tests:
25
+ image: python:3.9-alpine
26
+ script:
27
+ - pip install .[dev]
28
+ - pytest -s -vv
29
+
30
+ deploy_pypi:
31
+ stage: deploy
32
+ image: python:3.9-alpine
33
+ script:
34
+ - apk add --update --no-cache git
35
+ - pip install .[build]
36
+ - flit publish # use [flit](https://flit.pypa.io/) and FLIT_USERNAME/FLIT_PASSWORD env var
37
+ only:
38
+ - tags
@@ -0,0 +1,134 @@
1
+
2
+ # Code of Conduct
3
+
4
+ ## Our Pledge
5
+
6
+ We as members, contributors, and leaders pledge to make participation in our
7
+ community a harassment-free experience for everyone, regardless of age, body
8
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
9
+ identity and expression, level of experience, education, socio-economic status,
10
+ nationality, personal appearance, race, caste, color, religion, or sexual
11
+ identity and orientation.
12
+
13
+ We pledge to act and interact in ways that contribute to an open, welcoming,
14
+ diverse, inclusive, and healthy community.
15
+
16
+ ## Our Standards
17
+
18
+ Examples of behavior that contributes to a positive environment for our
19
+ community include:
20
+
21
+ * Demonstrating empathy and kindness toward other people
22
+ * Being respectful of differing opinions, viewpoints, and experiences
23
+ * Giving and gracefully accepting constructive feedback
24
+ * Accepting responsibility and apologizing to those affected by our mistakes,
25
+ and learning from the experience
26
+ * Focusing on what is best not just for us as individuals, but for the overall
27
+ community
28
+
29
+ Examples of unacceptable behavior include:
30
+
31
+ * The use of sexualized language or imagery, and sexual attention or advances of
32
+ any kind
33
+ * Trolling, insulting or derogatory comments, and personal or political attacks
34
+ * Public or private harassment
35
+ * Publishing others' private information, such as a physical or email address,
36
+ without their explicit permission
37
+ * Other conduct which could reasonably be considered inappropriate in a
38
+ professional setting
39
+
40
+ ## Enforcement Responsibilities
41
+
42
+ Community leaders are responsible for clarifying and enforcing our standards of
43
+ acceptable behavior and will take appropriate and fair corrective action in
44
+ response to any behavior that they deem inappropriate, threatening, offensive,
45
+ or harmful.
46
+
47
+ Community leaders have the right and responsibility to remove, edit, or reject
48
+ comments, commits, code, wiki edits, issues, and other contributions that are
49
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
50
+ decisions when appropriate.
51
+
52
+ ## Scope
53
+
54
+ This Code of Conduct applies within all community spaces, and also applies when
55
+ an individual is officially representing the community in public spaces.
56
+ Examples of representing our community include using an official e-mail address,
57
+ posting via an official social media account, or acting as an appointed
58
+ representative at an online or offline event.
59
+
60
+ ## Enforcement
61
+
62
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
63
+ reported to the community leaders responsible for enforcement at panieravide@riseup.net
64
+
65
+ All complaints will be reviewed and investigated promptly and fairly.
66
+
67
+ All community leaders are obligated to respect the privacy and security of the
68
+ reporter of any incident.
69
+
70
+ ## Enforcement Guidelines
71
+
72
+ Community leaders will follow these Community Impact Guidelines in determining
73
+ the consequences for any action they deem in violation of this Code of Conduct:
74
+
75
+ ### 1. Correction
76
+
77
+ **Community Impact**: Use of inappropriate language or other behavior deemed
78
+ unprofessional or unwelcome in the community.
79
+
80
+ **Consequence**: A private, written warning from community leaders, providing
81
+ clarity around the nature of the violation and an explanation of why the
82
+ behavior was inappropriate. A public apology may be requested.
83
+
84
+ ### 2. Warning
85
+
86
+ **Community Impact**: A violation through a single incident or series of
87
+ actions.
88
+
89
+ **Consequence**: A warning with consequences for continued behavior. No
90
+ interaction with the people involved, including unsolicited interaction with
91
+ those enforcing the Code of Conduct, for a specified period of time. This
92
+ includes avoiding interactions in community spaces as well as external channels
93
+ like social media. Violating these terms may lead to a temporary or permanent
94
+ ban.
95
+
96
+ ### 3. Temporary Ban
97
+
98
+ **Community Impact**: A serious violation of community standards, including
99
+ sustained inappropriate behavior.
100
+
101
+ **Consequence**: A temporary ban from any sort of interaction or public
102
+ communication with the community for a specified period of time. No public or
103
+ private interaction with the people involved, including unsolicited interaction
104
+ with those enforcing the Code of Conduct, is allowed during this period.
105
+ Violating these terms may lead to a permanent ban.
106
+
107
+ ### 4. Permanent Ban
108
+
109
+ **Community Impact**: Demonstrating a pattern of violation of community
110
+ standards, including sustained inappropriate behavior, harassment of an
111
+ individual, or aggression toward or disparagement of classes of individuals.
112
+
113
+ **Consequence**: A permanent ban from any sort of public interaction within the
114
+ community.
115
+
116
+ ## Attribution
117
+
118
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119
+ version 2.1, available at
120
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
121
+
122
+ Community Impact Guidelines were inspired by
123
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
124
+
125
+ For answers to common questions about this code of conduct, see the FAQ at
126
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
127
+ [https://www.contributor-covenant.org/translations][translations].
128
+
129
+ [homepage]: https://www.contributor-covenant.org
130
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
131
+ [Mozilla CoC]: https://github.com/mozilla/diversity
132
+ [FAQ]: https://www.contributor-covenant.org/faq
133
+ [translations]: https://www.contributor-covenant.org/translations
134
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Geovisio team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ .DEFAULT_GOAL := help
2
+
3
+ .PHONY: docs test type-check fmt ci
4
+
5
+ test: ## Run tests
6
+ pytest
7
+
8
+ type-check: ## Check all python types
9
+ mypy geopic_tag_reader/
10
+
11
+ fmt: ## Format code
12
+ black --fast .
13
+
14
+ ci: type-check fmt test ## Run all check like the ci
15
+
16
+ docs: ## Generates documentation from Typer embedded docs
17
+ python -m typer_cli ./geopic_tag_reader/main.py utils docs --name geopic-tag-reader --output docs/CLI_USAGE.md
18
+ lazydocs --overview-file API_USAGE.md --ignored-modules main --output-path docs/ geopic_tag_reader/
19
+
20
+ help: ## Print this help message
21
+ @grep -E '^[a-zA-Z_-]+:.*## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@@ -0,0 +1,173 @@
1
+ Metadata-Version: 2.1
2
+ Name: geopic-tag-reader
3
+ Version: 0.0.1
4
+ Summary: GeoPicTagReader
5
+ Author-email: Adrien PAVIE <panieravide@riseup.net>
6
+ Description-Content-Type: text/markdown
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Requires-Dist: typer ~= 0.7.0
9
+ Requires-Dist: Pillow ~= 9.4.0
10
+ Requires-Dist: xmltodict ~= 0.13.0
11
+ Requires-Dist: flit ~= 3.8.0 ; extra == "build"
12
+ Requires-Dist: black ~= 22.8.0 ; extra == "dev"
13
+ Requires-Dist: mypy ~= 1.0.0 ; extra == "dev"
14
+ Requires-Dist: pytest ~= 7.2.0 ; extra == "dev"
15
+ Requires-Dist: pytest-datafiles ~= 2.0.1 ; extra == "dev"
16
+ Requires-Dist: typer-cli ~= 0.0.13 ; extra == "dev"
17
+ Requires-Dist: lazydocs ~= 0.4.8 ; extra == "dev"
18
+ Requires-Dist: types-xmltodict ~= 0.13.0 ; extra == "dev"
19
+ Requires-Dist: types-Pillow ~= 9.4.0 ; extra == "dev"
20
+ Project-URL: Home, https://gitlab.com/geovisio/geo-picture-tag-reader
21
+ Provides-Extra: build
22
+ Provides-Extra: dev
23
+
24
+ # GeoPicTagReader
25
+
26
+ ![GeoVisio logo](https://gitlab.com/geovisio/api/-/raw/develop/images/logo_full.png)
27
+
28
+ Python library to extract standardized metadata from geolocated pictures EXIF metadata.
29
+
30
+ [[_TOC_]]
31
+
32
+
33
+ ## Features
34
+
35
+ This tool allows you to:
36
+
37
+ - Analyse various EXIF variables to extract standardized metadata for geolocated pictures applications
38
+
39
+
40
+ ## Install
41
+
42
+ GeoPicTagReader can be installed using two methods:
43
+
44
+ - From [PyPI](https://pypi.org/project/geopictagreader/), the Python central package repository
45
+ - Using this [Git repository](https://gitlab.com/geovisio/geo-picture-tag-reader)
46
+
47
+ ### From PyPI
48
+
49
+ Just launch this command:
50
+
51
+ ```bash
52
+ pip install geopic_tag_reader
53
+ ```
54
+
55
+ After this you should be able to use the CLI tool with the name `geopic-tag-reader`:
56
+
57
+ ```bash
58
+ geopic-tag-reader --help
59
+ ```
60
+
61
+ Alternatively, you can use [pipx](https://github.com/pypa/pipx) if you want all the script dependencies to be in a custom virtual env.
62
+
63
+ You need to [install pipx](https://pypa.github.io/pipx/installation/), then:
64
+
65
+ ```bash
66
+ pipx install geopic_tag_reader
67
+ ```
68
+
69
+ ### From Git repository
70
+
71
+ Download the repository:
72
+
73
+ ```bash
74
+ git clone https://gitlab.com/geovisio/geo-picture-tag-reader.git geopic_tag_reader
75
+ cd geopic_tag_reader/
76
+ ```
77
+
78
+ To avoid conflicts, it's considered a good practice to create a _[virtual environment](https://docs.python.org/3/library/venv.html)_ (or virtualenv). To do so, launch the following commands:
79
+
80
+ ```bash
81
+ # Create the virtual environment in a folder named "env"
82
+ python3 -m venv env
83
+
84
+ # Launches utilities to make environment available in your Bash
85
+ source ./env/bin/activate
86
+ ```
87
+
88
+ Then, install the dependencies using pip:
89
+
90
+ ```bash
91
+ pip install -e .
92
+ ```
93
+
94
+ You can also install the `dev` dependencies if necessary (to have lints, format, tests, ...):
95
+
96
+ ```bash
97
+ pip install -e .[dev]
98
+ ```
99
+
100
+ Then, you can use the `geopic-tag-reader` command:
101
+ ```bash
102
+ geopic-tag-reader --help
103
+ ```
104
+
105
+
106
+ ## Usage
107
+
108
+ This library can be used both from command-line or as Python module.
109
+
110
+ ### As command-line
111
+
112
+ To see all available commands:
113
+
114
+ ```bash
115
+ geopic-tag-reader --help
116
+ ```
117
+
118
+ [Full documentation is also available here](./docs/CLI_USAGE.md).
119
+
120
+ ### As Python library
121
+
122
+ In your own script, you can use:
123
+
124
+ ```python
125
+ from geopic_tag_reader import reader
126
+ from PIL import Image
127
+
128
+ # Open an image with Pillow
129
+ img = Image.open("my_picture.jpg")
130
+
131
+ # Read EXIF metadata
132
+ metadata = reader.readPictureMetadata(img)
133
+
134
+ # Print results
135
+ print(metadata)
136
+ ```
137
+
138
+ [Full documentation is also available here](./docs/API_USAGE.md).
139
+
140
+
141
+ ## Development
142
+
143
+ ### Tests
144
+
145
+ Tests are run using PyTest. You can simply run this command to launch tests:
146
+
147
+ ```bash
148
+ pytest
149
+ ```
150
+
151
+ ### Documentation
152
+
153
+ High-level documentation is handled by [Typer](https://typer.tiangolo.com/). You can update the generated `USAGE.md` file using this command:
154
+
155
+ ```bash
156
+ make docs
157
+ ```
158
+
159
+ ### Contributing
160
+
161
+ Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
162
+
163
+ Note that before opening a pull requests, you may want to check formatting and tests of your changes:
164
+
165
+ ```bash
166
+ make ci
167
+ ```
168
+
169
+
170
+ ## License
171
+
172
+ Copyright (c) GeoVisio team 2023, [released under MIT license](./LICENSE).
173
+
@@ -0,0 +1,149 @@
1
+ # GeoPicTagReader
2
+
3
+ ![GeoVisio logo](https://gitlab.com/geovisio/api/-/raw/develop/images/logo_full.png)
4
+
5
+ Python library to extract standardized metadata from geolocated pictures EXIF metadata.
6
+
7
+ [[_TOC_]]
8
+
9
+
10
+ ## Features
11
+
12
+ This tool allows you to:
13
+
14
+ - Analyse various EXIF variables to extract standardized metadata for geolocated pictures applications
15
+
16
+
17
+ ## Install
18
+
19
+ GeoPicTagReader can be installed using two methods:
20
+
21
+ - From [PyPI](https://pypi.org/project/geopictagreader/), the Python central package repository
22
+ - Using this [Git repository](https://gitlab.com/geovisio/geo-picture-tag-reader)
23
+
24
+ ### From PyPI
25
+
26
+ Just launch this command:
27
+
28
+ ```bash
29
+ pip install geopic_tag_reader
30
+ ```
31
+
32
+ After this you should be able to use the CLI tool with the name `geopic-tag-reader`:
33
+
34
+ ```bash
35
+ geopic-tag-reader --help
36
+ ```
37
+
38
+ Alternatively, you can use [pipx](https://github.com/pypa/pipx) if you want all the script dependencies to be in a custom virtual env.
39
+
40
+ You need to [install pipx](https://pypa.github.io/pipx/installation/), then:
41
+
42
+ ```bash
43
+ pipx install geopic_tag_reader
44
+ ```
45
+
46
+ ### From Git repository
47
+
48
+ Download the repository:
49
+
50
+ ```bash
51
+ git clone https://gitlab.com/geovisio/geo-picture-tag-reader.git geopic_tag_reader
52
+ cd geopic_tag_reader/
53
+ ```
54
+
55
+ To avoid conflicts, it's considered a good practice to create a _[virtual environment](https://docs.python.org/3/library/venv.html)_ (or virtualenv). To do so, launch the following commands:
56
+
57
+ ```bash
58
+ # Create the virtual environment in a folder named "env"
59
+ python3 -m venv env
60
+
61
+ # Launches utilities to make environment available in your Bash
62
+ source ./env/bin/activate
63
+ ```
64
+
65
+ Then, install the dependencies using pip:
66
+
67
+ ```bash
68
+ pip install -e .
69
+ ```
70
+
71
+ You can also install the `dev` dependencies if necessary (to have lints, format, tests, ...):
72
+
73
+ ```bash
74
+ pip install -e .[dev]
75
+ ```
76
+
77
+ Then, you can use the `geopic-tag-reader` command:
78
+ ```bash
79
+ geopic-tag-reader --help
80
+ ```
81
+
82
+
83
+ ## Usage
84
+
85
+ This library can be used both from command-line or as Python module.
86
+
87
+ ### As command-line
88
+
89
+ To see all available commands:
90
+
91
+ ```bash
92
+ geopic-tag-reader --help
93
+ ```
94
+
95
+ [Full documentation is also available here](./docs/CLI_USAGE.md).
96
+
97
+ ### As Python library
98
+
99
+ In your own script, you can use:
100
+
101
+ ```python
102
+ from geopic_tag_reader import reader
103
+ from PIL import Image
104
+
105
+ # Open an image with Pillow
106
+ img = Image.open("my_picture.jpg")
107
+
108
+ # Read EXIF metadata
109
+ metadata = reader.readPictureMetadata(img)
110
+
111
+ # Print results
112
+ print(metadata)
113
+ ```
114
+
115
+ [Full documentation is also available here](./docs/API_USAGE.md).
116
+
117
+
118
+ ## Development
119
+
120
+ ### Tests
121
+
122
+ Tests are run using PyTest. You can simply run this command to launch tests:
123
+
124
+ ```bash
125
+ pytest
126
+ ```
127
+
128
+ ### Documentation
129
+
130
+ High-level documentation is handled by [Typer](https://typer.tiangolo.com/). You can update the generated `USAGE.md` file using this command:
131
+
132
+ ```bash
133
+ make docs
134
+ ```
135
+
136
+ ### Contributing
137
+
138
+ Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
139
+
140
+ Note that before opening a pull requests, you may want to check formatting and tests of your changes:
141
+
142
+ ```bash
143
+ make ci
144
+ ```
145
+
146
+
147
+ ## License
148
+
149
+ Copyright (c) GeoVisio team 2023, [released under MIT license](./LICENSE).
@@ -0,0 +1,4 @@
1
+ title: API Reference
2
+ nav:
3
+ - Overview: API_USAGE.md
4
+ - ...
@@ -0,0 +1,23 @@
1
+ <!-- markdownlint-disable -->
2
+
3
+ # API Overview
4
+
5
+ ## Modules
6
+
7
+ - [`reader`](./reader.md#module-reader)
8
+
9
+ ## Classes
10
+
11
+ - [`reader.GeoPicTags`](./reader.md#class-geopictags): Tags associated to a geolocated picture
12
+ - [`reader.PartialExifException`](./reader.md#class-partialexifexception): Exception for partial / missing EXIF information from image
13
+
14
+ ## Functions
15
+
16
+ - [`reader.decodeMakeModel`](./reader.md#function-decodemakemodel): Python 2/3 compatible decoding of make/model field.
17
+ - [`reader.isExifTagUsable`](./reader.md#function-isexiftagusable): Is a given EXIF tag usable (not null and not an empty string)
18
+ - [`reader.readPictureMetadata`](./reader.md#function-readpicturemetadata): Extracts metadata from picture file
19
+
20
+
21
+ ---
22
+
23
+ _This file was automatically generated via [lazydocs](https://github.com/ml-tooling/lazydocs)._
@@ -0,0 +1,16 @@
1
+ # `geopic-tag-reader`
2
+
3
+ Reads EXIF metadata from a picture file, and prints results
4
+
5
+ **Usage**:
6
+
7
+ ```console
8
+ $ geopic-tag-reader [OPTIONS]
9
+ ```
10
+
11
+ **Options**:
12
+
13
+ * `--image PATH`: Path to your JPEG image file [required]
14
+ * `--install-completion`: Install completion for the current shell.
15
+ * `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
16
+ * `--help`: Show this message and exit.
@@ -0,0 +1,150 @@
1
+ <!-- markdownlint-disable -->
2
+
3
+ <a href="../geopic_tag_reader/reader.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
4
+
5
+ # <kbd>module</kbd> `reader`
6
+
7
+
8
+
9
+
10
+
11
+ ---
12
+
13
+ <a href="../geopic_tag_reader/reader.py#L42"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
14
+
15
+ ## <kbd>function</kbd> `readPictureMetadata`
16
+
17
+ ```python
18
+ readPictureMetadata(picture)
19
+ ```
20
+
21
+ Extracts metadata from picture file
22
+
23
+
24
+
25
+ **Args:**
26
+
27
+ - <b>`picture`</b> (PIL.Image): Picture file
28
+
29
+
30
+
31
+ **Returns:**
32
+
33
+ - <b>`GeoPicTags`</b>: Extracted metadata from picture
34
+
35
+
36
+ ---
37
+
38
+ <a href="../geopic_tag_reader/reader.py#L194"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
39
+
40
+ ## <kbd>function</kbd> `decodeMakeModel`
41
+
42
+ ```python
43
+ decodeMakeModel(value)
44
+ ```
45
+
46
+ Python 2/3 compatible decoding of make/model field.
47
+
48
+
49
+ ---
50
+
51
+ <a href="../geopic_tag_reader/reader.py#L205"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
52
+
53
+ ## <kbd>function</kbd> `isExifTagUsable`
54
+
55
+ ```python
56
+ isExifTagUsable(exif, tag, expectedType=<class 'str'>)
57
+ ```
58
+
59
+ Is a given EXIF tag usable (not null and not an empty string)
60
+
61
+
62
+
63
+ **Args:**
64
+
65
+ - <b>`exif`</b> (dict): The EXIF tags
66
+ - <b>`tag`</b> (str): The tag to check
67
+ - <b>`expectedType`</b> (class): The expected data type
68
+
69
+
70
+
71
+ **Returns:**
72
+
73
+ - <b>`bool`</b>: True if not empty
74
+
75
+
76
+ ---
77
+
78
+ <a href="../geopic_tag_reader/reader.py#L8"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
79
+
80
+ ## <kbd>class</kbd> `GeoPicTags`
81
+ Tags associated to a geolocated picture
82
+
83
+
84
+
85
+ **Attributes:**
86
+
87
+ - <b>`lat`</b> (float): GPS Latitude (in WGS84)
88
+ - <b>`lon`</b> (float): GPS Longitude (in WGS84)
89
+ - <b>`ts`</b> (float): The capture date (as POSIX timestamp)
90
+ - <b>`heading`</b> (int): Picture heading (in degrees, North = 0°, East = 90°, South = 180°, West = 270°)
91
+ - <b>`type`</b> (str): The kind of picture (flat, equirectangular)
92
+ - <b>`make`</b> (str): The camera manufacturer name
93
+ - <b>`model`</b> (str): The camera model name
94
+ - <b>`focal_length`</b> (float): The camera focal length (in mm)
95
+ - <b>`exif`</b> (dict[str, str]): Raw EXIF tags from picture
96
+
97
+ <a href="../<string>"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
98
+
99
+ ### <kbd>method</kbd> `__init__`
100
+
101
+ ```python
102
+ __init__(
103
+ lat: float,
104
+ lon: float,
105
+ ts: float,
106
+ heading: int,
107
+ type: str,
108
+ make: str,
109
+ model: str,
110
+ focal_length: float,
111
+ exif: Dict[str, str] = <factory>
112
+ ) → None
113
+ ```
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+ ---
124
+
125
+ <a href="../geopic_tag_reader/reader.py#L35"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
126
+
127
+ ## <kbd>class</kbd> `PartialExifException`
128
+ Exception for partial / missing EXIF information from image
129
+
130
+ <a href="../geopic_tag_reader/reader.py#L38"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
131
+
132
+ ### <kbd>method</kbd> `__init__`
133
+
134
+ ```python
135
+ __init__(msg)
136
+ ```
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+ ---
149
+
150
+ _This file was automatically generated via [lazydocs](https://github.com/ml-tooling/lazydocs)._
@@ -0,0 +1,4 @@
1
+ """
2
+ GeoPicTagReader
3
+ """
4
+ __version__ = "0.0.1"
@@ -0,0 +1,29 @@
1
+ import typer
2
+ from pathlib import Path
3
+ from geopic_tag_reader import reader
4
+ from PIL import Image
5
+
6
+ app = typer.Typer(help="GeoPicTagReader")
7
+
8
+
9
+ @app.command()
10
+ def read(
11
+ image: Path = typer.Option(..., help="Path to your JPEG image file"),
12
+ ):
13
+ """Reads EXIF metadata from a picture file, and prints results"""
14
+
15
+ img = Image.open(image)
16
+ metadata = reader.readPictureMetadata(img)
17
+
18
+ print("Latitude:", metadata.lat)
19
+ print("Longitude:", metadata.lon)
20
+ print("Timestamp:", metadata.ts)
21
+ print("Heading:", metadata.heading)
22
+ print("Type:", metadata.type)
23
+ print("Make:", metadata.make)
24
+ print("Model:", metadata.model)
25
+ print("Focal length:", metadata.focal_length)
26
+
27
+
28
+ if __name__ == "__main__":
29
+ app()
@@ -0,0 +1,231 @@
1
+ from PIL import Image, ExifTags
2
+ import xmltodict
3
+ import datetime
4
+ from dataclasses import dataclass, field
5
+ from typing import Dict
6
+
7
+
8
+ @dataclass
9
+ class GeoPicTags:
10
+ """Tags associated to a geolocated picture
11
+
12
+ Attributes:
13
+ lat (float): GPS Latitude (in WGS84)
14
+ lon (float): GPS Longitude (in WGS84)
15
+ ts (float): The capture date (as POSIX timestamp)
16
+ heading (int): Picture heading (in degrees, North = 0°, East = 90°, South = 180°, West = 270°)
17
+ type (str): The kind of picture (flat, equirectangular)
18
+ make (str): The camera manufacturer name
19
+ model (str): The camera model name
20
+ focal_length (float): The camera focal length (in mm)
21
+ exif (dict[str, str]): Raw EXIF tags from picture
22
+ """
23
+
24
+ lat: float
25
+ lon: float
26
+ ts: float
27
+ heading: int
28
+ type: str
29
+ make: str
30
+ model: str
31
+ focal_length: float
32
+ exif: Dict[str, str] = field(default_factory=lambda: {})
33
+
34
+
35
+ class PartialExifException(Exception):
36
+ """Exception for partial / missing EXIF information from image"""
37
+
38
+ def __init__(self, msg):
39
+ super().__init__(msg)
40
+
41
+
42
+ def readPictureMetadata(picture):
43
+ """Extracts metadata from picture file
44
+
45
+ Args:
46
+ picture (PIL.Image): Picture file
47
+
48
+ Returns:
49
+ GeoPicTags: Extracted metadata from picture
50
+ """
51
+
52
+ data = {}
53
+
54
+ info = picture._getexif()
55
+ if info:
56
+ for tag, value in info.items():
57
+ decoded = ExifTags.TAGS.get(tag, tag)
58
+ if decoded == "GPSInfo":
59
+ for t in value:
60
+ sub_decoded = ExifTags.GPSTAGS.get(t, t)
61
+ data[sub_decoded] = value[t]
62
+ else:
63
+ data[decoded] = value
64
+
65
+ # Read XMP tags
66
+ for segment, content in picture.applist:
67
+ if segment == "APP1":
68
+ marker, body = content.split(b"\x00", 1)
69
+ if marker == b"http://ns.adobe.com/xap/1.0/":
70
+ body = body.strip(b"\00")
71
+ description = xmltodict.parse(body)["x:xmpmeta"]["rdf:RDF"][
72
+ "rdf:Description"
73
+ ]
74
+ if isinstance(description, list):
75
+ # there can be several rdf:Description, if that's the case, we merge them all
76
+ description = {k: v for d in description for k, v in d.items()}
77
+ data = data | description
78
+
79
+ # Cleanup XMP tags with @
80
+ for k in list(data):
81
+ if k.startswith("@"):
82
+ data[k[1:]] = data[k]
83
+ del data[k]
84
+
85
+ # Parse latitude/longitude
86
+ if (
87
+ isExifTagUsable(data, "GPSLatitude", tuple)
88
+ and isExifTagUsable(data, "GPSLongitude", tuple)
89
+ and isExifTagUsable(data, "GPSLatitudeRef")
90
+ and isExifTagUsable(data, "GPSLongitudeRef")
91
+ ):
92
+ latRaw = data["GPSLatitude"]
93
+ lat = (-1 if data["GPSLatitudeRef"] == "S" else 1) * (
94
+ float(latRaw[0]) + float(latRaw[1]) / 60 + float(latRaw[2]) / 3600
95
+ )
96
+
97
+ lonRaw = data["GPSLongitude"]
98
+ lon = (-1 if data["GPSLongitudeRef"] == "W" else 1) * (
99
+ float(lonRaw[0]) + float(lonRaw[1]) / 60 + float(lonRaw[2]) / 3600
100
+ )
101
+ else:
102
+ raise PartialExifException(
103
+ "No GPS coordinates or broken coordinates in picture EXIF tags"
104
+ )
105
+
106
+ # Parse date/time
107
+ if isExifTagUsable(data, "GPSTimeStamp", tuple) and isExifTagUsable(
108
+ data, "GPSDateStamp"
109
+ ):
110
+ timeRaw = data["GPSTimeStamp"]
111
+ dateRaw = data["GPSDateStamp"].replace(":", "-").replace("\x00", "")
112
+ msRaw = (
113
+ data["SubSecTimeOriginal"]
114
+ if isExifTagUsable(data, "SubSecTimeOriginal", float)
115
+ else "0"
116
+ )
117
+ d = datetime.datetime.combine(
118
+ datetime.date.fromisoformat(dateRaw),
119
+ datetime.time(
120
+ int(timeRaw[0]),
121
+ int(timeRaw[1]),
122
+ int(timeRaw[2]),
123
+ int(msRaw[:6].ljust(6, "0")),
124
+ tzinfo=datetime.timezone.utc,
125
+ ),
126
+ )
127
+ elif isExifTagUsable(data, "DateTimeOriginal"):
128
+ dateRaw = data["DateTimeOriginal"].split(" ")[0].replace(":", "-")
129
+ timeRaw = data["DateTimeOriginal"].split(" ")[1].split(":")
130
+ msRaw = (
131
+ data["SubSecTimeOriginal"]
132
+ if isExifTagUsable(data, "SubSecTimeOriginal", float)
133
+ else "0"
134
+ )
135
+ d = datetime.datetime.combine(
136
+ datetime.date.fromisoformat(dateRaw),
137
+ datetime.time(
138
+ int(timeRaw[0]),
139
+ int(timeRaw[1]),
140
+ int(timeRaw[2]),
141
+ int(msRaw[:6].ljust(6, "0")),
142
+ tzinfo=datetime.timezone.utc,
143
+ ),
144
+ )
145
+ else:
146
+ raise PartialExifException("No date in picture EXIF tags")
147
+
148
+ # Heading
149
+ heading = None
150
+ if isExifTagUsable(data, "GPano:PoseHeadingDegrees", float) and isExifTagUsable(
151
+ data, "GPSImgDirection", float
152
+ ):
153
+ gpsDir = int(round(data["GPSImgDirection"]))
154
+ gpanoHeading = int(round(float(data["GPano:PoseHeadingDegrees"])))
155
+ if gpsDir > 0 and gpanoHeading == 0:
156
+ heading = gpsDir
157
+ elif gpsDir == 0 and gpanoHeading > 0:
158
+ heading = gpanoHeading
159
+ else:
160
+ if gpsDir == gpanoHeading:
161
+ heading = gpanoHeading
162
+ else:
163
+ raise PartialExifException(
164
+ "Contradicting heading values in EXIF PoseHeadingDegrees and GPSImgDirection tags"
165
+ )
166
+ elif isExifTagUsable(data, "GPano:PoseHeadingDegrees", float):
167
+ heading = int(round(float(data["GPano:PoseHeadingDegrees"])))
168
+ elif isExifTagUsable(data, "GPSImgDirection", float):
169
+ heading = int(round(data["GPSImgDirection"]))
170
+
171
+ # Make and model
172
+ make = decodeMakeModel(data["Make"]).strip() if "Make" in data else None
173
+ model = decodeMakeModel(data["Model"]).strip() if "Model" in data else None
174
+ if model is not None and model is not None:
175
+ model = model.replace(make, "").strip()
176
+
177
+ return GeoPicTags(
178
+ lat,
179
+ lon,
180
+ d.timestamp(),
181
+ heading,
182
+ data["GPano:ProjectionType"]
183
+ if isExifTagUsable(data, "GPano:ProjectionType")
184
+ else "flat",
185
+ make,
186
+ model,
187
+ float(data["FocalLength"])
188
+ if isExifTagUsable(data, "FocalLength", float)
189
+ else None,
190
+ data,
191
+ )
192
+
193
+
194
+ def decodeMakeModel(value):
195
+ """Python 2/3 compatible decoding of make/model field."""
196
+ if hasattr(value, "decode"):
197
+ try:
198
+ return value.decode("utf-8").replace("\x00", "")
199
+ except UnicodeDecodeError:
200
+ return None
201
+ else:
202
+ return value.replace("\x00", "")
203
+
204
+
205
+ def isExifTagUsable(exif, tag, expectedType=str):
206
+ """Is a given EXIF tag usable (not null and not an empty string)
207
+
208
+ Args:
209
+ exif (dict): The EXIF tags
210
+ tag (str): The tag to check
211
+ expectedType (class): The expected data type
212
+
213
+ Returns:
214
+ bool: True if not empty
215
+ """
216
+
217
+ try:
218
+ if not tag in exif:
219
+ return False
220
+ elif not (expectedType == float or isinstance(exif[tag], expectedType)):
221
+ return False
222
+ elif not (
223
+ expectedType != str or len(exif[tag].strip().replace("\x00", "")) > 0
224
+ ):
225
+ return False
226
+ elif not (expectedType != float or float(exif[tag]) is not None):
227
+ return False
228
+ else:
229
+ return True
230
+ except ValueError:
231
+ return False
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["flit_core ~= 3.8,<4"]
3
+ build-backend = "flit_core.buildapi"
4
+
5
+ [project]
6
+ name = "geopic-tag-reader"
7
+ authors = [
8
+ {name = "Adrien PAVIE", email = "panieravide@riseup.net"},
9
+ ]
10
+ readme = "README.md"
11
+ license = {file = "LICENSE"}
12
+ classifiers = ["License :: OSI Approved :: MIT License"]
13
+ dynamic = ["version", "description"]
14
+ dependencies = [
15
+ "typer ~= 0.7.0",
16
+ "Pillow ~= 9.4.0",
17
+ "xmltodict ~= 0.13.0",
18
+ ]
19
+
20
+ [project.urls]
21
+ Home = "https://gitlab.com/geovisio/geo-picture-tag-reader"
22
+
23
+ [project.scripts]
24
+ geopic-tag-reader="geopic_tag_reader.main:app"
25
+
26
+ [project.optional-dependencies]
27
+ dev = [
28
+ "black ~= 22.8.0",
29
+ "mypy ~= 1.0.0",
30
+ "pytest ~= 7.2.0",
31
+ "pytest-datafiles ~= 2.0.1",
32
+ "typer-cli ~= 0.0.13",
33
+ "lazydocs ~= 0.4.8",
34
+ "types-xmltodict ~= 0.13.0",
35
+ "types-Pillow ~= 9.4.0",
36
+ ]
37
+ build = ["flit ~= 3.8.0"]
38
+
39
+ [tool.pytest.ini_options]
40
+ addopts = [
41
+ "--import-mode=importlib",
42
+ ]
File without changes
@@ -0,0 +1,192 @@
1
+ import os
2
+ import pytest
3
+ from PIL import Image
4
+ from geopic_tag_reader import reader
5
+
6
+ FIXTURE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "fixtures")
7
+
8
+
9
+ def assertGeoPicTagsEquals(gpt, expectedDict):
10
+ assert gpt.lat == expectedDict.get("lat")
11
+ assert gpt.lon == expectedDict.get("lon")
12
+ assert gpt.ts == expectedDict.get("ts")
13
+ assert gpt.heading == expectedDict.get("heading")
14
+ assert gpt.type == expectedDict.get("type")
15
+ assert gpt.make == expectedDict.get("make")
16
+ assert gpt.model == expectedDict.get("model")
17
+ assert gpt.focal_length == expectedDict.get("focal_length")
18
+ assert len(gpt.exif) > 0
19
+
20
+
21
+ @pytest.mark.datafiles(os.path.join(FIXTURE_DIR, "1.jpg"))
22
+ def test_readPictureMetadata(datafiles):
23
+ result = reader.readPictureMetadata(Image.open(str(datafiles) + "/1.jpg"))
24
+ assertGeoPicTagsEquals(
25
+ result,
26
+ {
27
+ "lat": 49.00688961988304,
28
+ "lon": 1.9191854417991367,
29
+ "ts": 1627550214.0,
30
+ "heading": 349,
31
+ "type": "equirectangular",
32
+ "make": "GoPro",
33
+ "model": "Max",
34
+ "focal_length": 3,
35
+ },
36
+ )
37
+
38
+
39
+ @pytest.mark.datafiles(os.path.join(FIXTURE_DIR, "a1.jpg"))
40
+ def test_readPictureMetadata_negCoords(datafiles):
41
+ result = reader.readPictureMetadata(Image.open(str(datafiles) + "/a1.jpg"))
42
+ assertGeoPicTagsEquals(
43
+ result,
44
+ {
45
+ "lat": 48.33756428166505,
46
+ "lon": -1.9331088333333333,
47
+ "ts": 1652453580.0,
48
+ "heading": 32,
49
+ "type": "equirectangular",
50
+ "make": "GoPro",
51
+ "model": "Max",
52
+ "focal_length": 3,
53
+ },
54
+ )
55
+
56
+
57
+ @pytest.mark.datafiles(os.path.join(FIXTURE_DIR, "b1.jpg"))
58
+ def test_readPictureMetadata_flat(datafiles):
59
+ result = reader.readPictureMetadata(Image.open(str(datafiles) + "/b1.jpg"))
60
+ assertGeoPicTagsEquals(
61
+ result,
62
+ {
63
+ "lat": 48.139852239480945,
64
+ "lon": -1.9499731060073981,
65
+ "ts": 1429976268.0,
66
+ "heading": 155,
67
+ "type": "flat",
68
+ "make": "OLYMPUS IMAGING CORP.",
69
+ "model": "SP-720UZ",
70
+ "focal_length": 4.66,
71
+ },
72
+ )
73
+
74
+
75
+ @pytest.mark.datafiles(os.path.join(FIXTURE_DIR, "c1.jpg"))
76
+ def test_readPictureMetadata_flat2(datafiles):
77
+ result = reader.readPictureMetadata(Image.open(str(datafiles) + "/c1.jpg"))
78
+ assertGeoPicTagsEquals(
79
+ result,
80
+ {
81
+ "lat": 48.85779642035038,
82
+ "lon": 2.3392783047650747,
83
+ "ts": 1430744932.0,
84
+ "heading": 302,
85
+ "type": "flat",
86
+ "make": "Canon",
87
+ "model": "EOS 6D0",
88
+ "focal_length": 35.0,
89
+ },
90
+ )
91
+
92
+
93
+ @pytest.mark.datafiles(os.path.join(FIXTURE_DIR, "d1.jpg"))
94
+ def test_readPictureMetadata_xmpHeading(datafiles):
95
+ result = reader.readPictureMetadata(Image.open(str(datafiles) + "/d1.jpg"))
96
+ assertGeoPicTagsEquals(
97
+ result,
98
+ {
99
+ "lat": 50.87070833333333,
100
+ "lon": -1.5260916666666666,
101
+ "ts": 1600008019.0,
102
+ "heading": 67,
103
+ "type": "equirectangular",
104
+ "make": "Google",
105
+ "model": "Pixel 3",
106
+ "focal_length": None,
107
+ },
108
+ )
109
+
110
+
111
+ @pytest.mark.datafiles(os.path.join(FIXTURE_DIR, "e1.jpg"))
112
+ def test_readPictureMetadata_noHeading(datafiles):
113
+ result = reader.readPictureMetadata(Image.open(str(datafiles) + "/e1.jpg"))
114
+ assertGeoPicTagsEquals(
115
+ result,
116
+ {
117
+ "lat": 48.15506638888889,
118
+ "lon": -1.6844680555555556,
119
+ "ts": 1666166194.0,
120
+ "heading": None,
121
+ "type": "flat",
122
+ "make": "SONY",
123
+ "model": "FDR-X1000V",
124
+ "focal_length": 2.8,
125
+ },
126
+ )
127
+
128
+
129
+ @pytest.mark.datafiles(os.path.join(FIXTURE_DIR, "img_Ricoh_Theta.jpg"))
130
+ def test_readPictureMetadata_ricoh_theta(datafiles):
131
+ for f in datafiles.listdir():
132
+ result = reader.readPictureMetadata(Image.open(str(f)))
133
+ assertGeoPicTagsEquals(
134
+ result,
135
+ {
136
+ "focal_length": 0.75,
137
+ "heading": 270,
138
+ "lat": 48.83930905577957,
139
+ "lon": 2.3205357914890987,
140
+ "make": "RICOH",
141
+ "model": "THETA m15",
142
+ "ts": 1458911533.0,
143
+ "type": "equirectangular",
144
+ },
145
+ )
146
+
147
+
148
+ @pytest.mark.datafiles(os.path.join(FIXTURE_DIR, "img_V4MPack.jpg"))
149
+ def test_readPictureMetadata_v4mpack(datafiles):
150
+ for f in datafiles.listdir():
151
+ result = reader.readPictureMetadata(Image.open(str(f)))
152
+ assertGeoPicTagsEquals(
153
+ result,
154
+ {
155
+ "focal_length": None,
156
+ "heading": 64,
157
+ "lat": 47.08506017299737,
158
+ "lon": -1.2761512389983616,
159
+ "make": "STFMANI",
160
+ "model": "V4MPOD 1",
161
+ "ts": 1555417213.0,
162
+ "type": "equirectangular",
163
+ },
164
+ )
165
+
166
+
167
+ @pytest.mark.datafiles(os.path.join(FIXTURE_DIR, "IMG_20210720_161352.jpg"))
168
+ def test_readPictureMetadata_a5000(datafiles):
169
+ result = reader.readPictureMetadata(
170
+ Image.open(str(datafiles) + "/IMG_20210720_161352.jpg")
171
+ )
172
+ assertGeoPicTagsEquals(
173
+ result,
174
+ {
175
+ "focal_length": 4.103,
176
+ "heading": 355,
177
+ "lat": 48.96280504578332,
178
+ "lon": 2.51197323068765,
179
+ "make": "OnePlus",
180
+ "model": "ONEPLUS A5000",
181
+ "ts": 1626797632.0,
182
+ "type": "flat",
183
+ },
184
+ )
185
+
186
+
187
+ @pytest.mark.datafiles(os.path.join(FIXTURE_DIR, "IMG_20210720_144918.jpg"))
188
+ def test_readPictureMetadata_a5000_2(datafiles):
189
+ with pytest.raises(reader.PartialExifException) as e_info:
190
+ result = reader.readPictureMetadata(
191
+ Image.open(str(datafiles) + "/IMG_20210720_144918.jpg")
192
+ )