@capacitor-community/exif 6.0.0

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,17 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CapacitorCommunityExif'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '13.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) COPYRIGHT_YEAR COPYRIGHT_HOLDER
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.
package/Package.swift ADDED
@@ -0,0 +1,28 @@
1
+ // swift-tools-version: 5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "CapacitorCommunityExif",
6
+ platforms: [.iOS(.v13)],
7
+ products: [
8
+ .library(
9
+ name: "CapacitorCommunityExif",
10
+ targets: ["ExifPlugin"])
11
+ ],
12
+ dependencies: [
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", branch: "main")
14
+ ],
15
+ targets: [
16
+ .target(
17
+ name: "ExifPlugin",
18
+ dependencies: [
19
+ .product(name: "Capacitor", package: "capacitor-swift-pm"),
20
+ .product(name: "Cordova", package: "capacitor-swift-pm")
21
+ ],
22
+ path: "ios/Sources/ExifPlugin"),
23
+ .testTarget(
24
+ name: "ExifPluginTests",
25
+ dependencies: ["ExifPlugin"],
26
+ path: "ios/Tests/ExifPluginTests")
27
+ ]
28
+ )
package/README.md ADDED
@@ -0,0 +1,172 @@
1
+ <p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p>
2
+ <h3 align="center">Capacitor Exif Plugin</h3>
3
+ <p align="center"><strong><code>@capacitor-community/exif</code></strong></p>
4
+ <p align="center">
5
+ Capacitor community plugin for interacting with image exif metadata
6
+ </p>
7
+
8
+ <p align="center">
9
+ <img src="https://img.shields.io/maintenance/yes/2024?style=flat-square" />
10
+ <a href="https://github.com/capacitor-community/exif/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/workflow/status/capacitor-community/exif/CI?style=flat-square" /></a>
11
+ <a href="https://www.npmjs.com/package/@capacitor-community/exif"><img src="https://img.shields.io/npm/l/@capacitor-community/exif?style=flat-square" /></a>
12
+ <br>
13
+ <a href="https://www.npmjs.com/package/@capacitor-community/exif"><img src="https://img.shields.io/npm/dw/@capacitor-community/exif?style=flat-square" /></a>
14
+ <a href="https://www.npmjs.com/package/@capacitor-community/exif"><img src="https://img.shields.io/npm/v/@capacitor-community/exif?style=flat-square" /></a>
15
+ <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
16
+ <a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-0-orange?style=flat-square" /></a>
17
+ <!-- ALL-CONTRIBUTORS-BADGE:END -->
18
+ </p>
19
+
20
+ # Table of Contents
21
+
22
+ - [Maintainers](#maintainers)
23
+ - [About](#about)
24
+ - [Plugin versions](#plugin-versions)
25
+ - [Supported Platforms](#supported-platforms)
26
+ - [Installation](#installation)
27
+ - [Configuration](#configuration)
28
+ - [API](#api)
29
+ - [Troubleshooting](#troubleshooting)
30
+
31
+ ## Maintainers
32
+
33
+ | Maintainer | GitHub | Active |
34
+ | ---------- | ------------------------------- | ------ |
35
+ | ryaa | [ryaa](https://github.com/ryaa) | yes |
36
+
37
+ ## About
38
+
39
+ This plugins allows reading and setting coordinates to image files.
40
+ This plugin has been primarity implemented to enhance other plugins which require coordinates to be added to images, for example https://github.com/capacitor-community/camera-preview/issues/164.
41
+
42
+ **Features:**
43
+
44
+ - support reading coordinates from image files
45
+ - support setting coordinates to image files
46
+ - supports Android and iOS platforms
47
+
48
+ **NOTE**: The plugin version 6.0.0 is compatible with Capacitor 6
49
+
50
+ ## Plugin versions
51
+
52
+ | Capacitor version | Plugin version |
53
+ | ----------------- | -------------- |
54
+ | 6.x | 6.x |
55
+
56
+ ## Supported Platforms
57
+
58
+ - iOS
59
+ - Android
60
+
61
+ ## Installation
62
+
63
+ ```bash
64
+ npm install @capacitor-community/exif
65
+ npx cap sync
66
+ ```
67
+
68
+ ## Configuration
69
+
70
+ ### Android
71
+ This plugin will use the following project variables (defined in your app's variables.gradle file):
72
+ ```
73
+ androidxExifInterfaceVersion: version of androidx.exifinterface:exifinterface (default: 1.3.6)
74
+ ```
75
+
76
+ ## API
77
+
78
+ <docgen-index>
79
+
80
+ * [`setCoordinates(...)`](#setcoordinates)
81
+ * [`getCoordinates(...)`](#getcoordinates)
82
+ * [Interfaces](#interfaces)
83
+
84
+ </docgen-index>
85
+
86
+
87
+ <docgen-api>
88
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
89
+
90
+ ### setCoordinates(...)
91
+
92
+ ```typescript
93
+ setCoordinates(options: SetCoordinatesOptions) => Promise<void>
94
+ ```
95
+
96
+ Set the coordinates to the image EXIF metadata.
97
+
98
+ | Param | Type |
99
+ | ------------- | ----------------------------------------------------------------------- |
100
+ | **`options`** | <code><a href="#setcoordinatesoptions">SetCoordinatesOptions</a></code> |
101
+
102
+ **Since:** 6.0.0
103
+
104
+ --------------------
105
+
106
+
107
+ ### getCoordinates(...)
108
+
109
+ ```typescript
110
+ getCoordinates(options: GetCoordinatesOptions) => Promise<{ lat: number; lng: number; } | undefined>
111
+ ```
112
+
113
+ Get the coordinates from the image EXIF metadata.
114
+
115
+ | Param | Type |
116
+ | ------------- | ----------------------------------------------------------------------- |
117
+ | **`options`** | <code><a href="#getcoordinatesoptions">GetCoordinatesOptions</a></code> |
118
+
119
+ **Returns:** <code>Promise&lt;{ lat: number; lng: number; }&gt;</code>
120
+
121
+ **Since:** 6.0.0
122
+
123
+ --------------------
124
+
125
+
126
+ ### Interfaces
127
+
128
+
129
+ #### SetCoordinatesOptions
130
+
131
+ | Prop | Type | Description | Since |
132
+ | ----------------- | ------------------- | ------------------------------------------------------------------ | ----- |
133
+ | **`pathToImage`** | <code>string</code> | The path to the image to set the coordinates to the EXIF metadata. | 6.0.0 |
134
+ | **`lat`** | <code>number</code> | The latitude of the image coordinates. | 6.0.0 |
135
+ | **`lng`** | <code>number</code> | The longitude of the image coordinates. | 6.0.0 |
136
+
137
+
138
+ #### GetCoordinatesOptions
139
+
140
+ | Prop | Type | Description | Since |
141
+ | ----------------- | ------------------- | ---------------------------------------------------------------- | ----- |
142
+ | **`pathToImage`** | <code>string</code> | The path to the image to get the coordinates from EXIF metadata. | 6.0.0 |
143
+
144
+ </docgen-api>
145
+
146
+ ## Usage
147
+
148
+ ### Set coordinates to image file
149
+
150
+ ```
151
+ import { Exif } from '@capacitor-community/exif';
152
+
153
+ const options: SetCoordinatesOptions = {
154
+ pathToImage,
155
+ lat,
156
+ lng
157
+ };
158
+ await this.exifPlugin.setCoordinates(options);
159
+ ```
160
+
161
+ ### Read coordinates from image file
162
+
163
+ ```
164
+ import { Exif } from '@capacitor-community/exif';
165
+
166
+ const options: GetCoordinatesOptions = { pathToImage };
167
+ const coordinates: {
168
+ lat: number;
169
+ lng: number;
170
+ } | undefined = await this.exifPlugin.getCoordinates(options);
171
+ ```
172
+
@@ -0,0 +1,60 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
6
+ androidxExifInterfaceVersion = project.hasProperty('androidxExifInterfaceVersion') ? rootProject.ext.androidxExifInterfaceVersion : '1.3.6'
7
+ }
8
+
9
+ buildscript {
10
+ repositories {
11
+ google()
12
+ mavenCentral()
13
+ }
14
+ dependencies {
15
+ classpath 'com.android.tools.build:gradle:8.2.1'
16
+ }
17
+ }
18
+
19
+ apply plugin: 'com.android.library'
20
+
21
+ android {
22
+ namespace "com.ryltsov.alex.plugins.exif"
23
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
24
+ defaultConfig {
25
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
26
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
27
+ versionCode 1
28
+ versionName "1.0"
29
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
30
+ }
31
+ buildTypes {
32
+ release {
33
+ minifyEnabled false
34
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
35
+ }
36
+ }
37
+ lintOptions {
38
+ abortOnError false
39
+ }
40
+ compileOptions {
41
+ sourceCompatibility JavaVersion.VERSION_17
42
+ targetCompatibility JavaVersion.VERSION_17
43
+ }
44
+ }
45
+
46
+ repositories {
47
+ google()
48
+ mavenCentral()
49
+ }
50
+
51
+
52
+ dependencies {
53
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
54
+ implementation project(':capacitor-android')
55
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
56
+ implementation "androidx.exifinterface:exifinterface:$androidxExifInterfaceVersion"
57
+ testImplementation "junit:junit:$junitVersion"
58
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
59
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
60
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,38 @@
1
+ package com.ryltsov.alex.plugins.exif;
2
+
3
+ import android.net.Uri;
4
+ import android.util.Log;
5
+
6
+ import androidx.exifinterface.media.ExifInterface;
7
+
8
+ import java.io.IOException;
9
+
10
+ public class Exif {
11
+
12
+ public void setCoordinates(String pathToImage, double latitude, double longitude) throws IOException {
13
+
14
+ Uri fileUri = Uri.parse(pathToImage);
15
+ // Convert the file:// URI to a file path string
16
+ String filePath = fileUri.getPath();
17
+ // Create an ExifInterface instance using the file path
18
+ ExifInterface exif = new ExifInterface(filePath);
19
+ exif.setLatLong(latitude, longitude);
20
+ // Save the changes
21
+ exif.saveAttributes();
22
+
23
+ }
24
+
25
+
26
+ public double[] getCoordinates(String pathToImage) throws IOException {
27
+
28
+ Uri fileUri = Uri.parse(pathToImage);
29
+ // Convert the file:// URI to a file path string
30
+ String filePath = fileUri.getPath();
31
+ // Create an ExifInterface instance using the file path
32
+ ExifInterface exif = new ExifInterface(filePath);
33
+
34
+ return exif.getLatLong();
35
+
36
+ }
37
+
38
+ }
@@ -0,0 +1,79 @@
1
+ package com.ryltsov.alex.plugins.exif;
2
+
3
+ import android.util.Log;
4
+
5
+ import com.getcapacitor.JSObject;
6
+ import com.getcapacitor.Plugin;
7
+ import com.getcapacitor.PluginCall;
8
+ import com.getcapacitor.PluginMethod;
9
+ import com.getcapacitor.annotation.CapacitorPlugin;
10
+
11
+ @CapacitorPlugin(name = "Exif")
12
+ public class ExifPlugin extends Plugin {
13
+
14
+ private static final String TAG = "ExifPlugin";
15
+
16
+ private final Exif implementation = new Exif();
17
+
18
+ @PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
19
+ public void setCoordinates(final PluginCall call) {
20
+
21
+ if (!call.getData().has("pathToImage")) {
22
+ call.reject("Must provide an pathToImage");
23
+ return;
24
+ }
25
+ if (!call.getData().has("lat")) {
26
+ call.reject("Must provide an lat");
27
+ return;
28
+ }
29
+ if (!call.getData().has("lng")) {
30
+ call.reject("Must provide an lng");
31
+ return;
32
+ }
33
+
34
+ String pathToImage = call.getString("pathToImage");
35
+ double latitude = call.getDouble("lat");
36
+ double longitude = call.getDouble("lng");
37
+
38
+ try {
39
+ implementation.setCoordinates(pathToImage, latitude, longitude);
40
+ } catch (Exception e) {
41
+ Log.e(TAG, "Error setting GPS data to image", e);
42
+ call.reject(e.getLocalizedMessage(), null, e);
43
+ return;
44
+ }
45
+
46
+ call.resolve();
47
+ }
48
+
49
+ @PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
50
+ public void getCoordinates(final PluginCall call) {
51
+
52
+ if (!call.getData().has("pathToImage")) {
53
+ call.reject("Must provide an pathToImage");
54
+ return;
55
+ }
56
+
57
+ String pathToImage = call.getString("pathToImage");
58
+
59
+ double[] latLong = null;
60
+ try {
61
+ latLong = implementation.getCoordinates(pathToImage);
62
+ } catch (Exception e) {
63
+ Log.e(TAG, "Error getting GPS data from image", e);
64
+ call.reject(e.getLocalizedMessage(), null, e);
65
+ return;
66
+ }
67
+ if ((latLong != null ? latLong.length : 0) == 2) {
68
+ JSObject ret = new JSObject();
69
+ double latitude = latLong[0];
70
+ double longitude = latLong[1];
71
+ ret.put("lat", latitude);
72
+ ret.put("lng", longitude);
73
+ call.resolve(ret);
74
+ return;
75
+ }
76
+ call.resolve();
77
+ }
78
+
79
+ }
File without changes
package/dist/docs.json ADDED
@@ -0,0 +1,128 @@
1
+ {
2
+ "api": {
3
+ "name": "ExifPlugin",
4
+ "slug": "exifplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "setCoordinates",
10
+ "signature": "(options: SetCoordinatesOptions) => Promise<void>",
11
+ "parameters": [
12
+ {
13
+ "name": "options",
14
+ "docs": "",
15
+ "type": "SetCoordinatesOptions"
16
+ }
17
+ ],
18
+ "returns": "Promise<void>",
19
+ "tags": [
20
+ {
21
+ "name": "since",
22
+ "text": "6.0.0"
23
+ }
24
+ ],
25
+ "docs": "Set the coordinates to the image EXIF metadata.",
26
+ "complexTypes": [
27
+ "SetCoordinatesOptions"
28
+ ],
29
+ "slug": "setcoordinates"
30
+ },
31
+ {
32
+ "name": "getCoordinates",
33
+ "signature": "(options: GetCoordinatesOptions) => Promise<{ lat: number; lng: number; } | undefined>",
34
+ "parameters": [
35
+ {
36
+ "name": "options",
37
+ "docs": "",
38
+ "type": "GetCoordinatesOptions"
39
+ }
40
+ ],
41
+ "returns": "Promise<{ lat: number; lng: number; } | undefined>",
42
+ "tags": [
43
+ {
44
+ "name": "since",
45
+ "text": "6.0.0"
46
+ }
47
+ ],
48
+ "docs": "Get the coordinates from the image EXIF metadata.",
49
+ "complexTypes": [
50
+ "GetCoordinatesOptions"
51
+ ],
52
+ "slug": "getcoordinates"
53
+ }
54
+ ],
55
+ "properties": []
56
+ },
57
+ "interfaces": [
58
+ {
59
+ "name": "SetCoordinatesOptions",
60
+ "slug": "setcoordinatesoptions",
61
+ "docs": "",
62
+ "tags": [],
63
+ "methods": [],
64
+ "properties": [
65
+ {
66
+ "name": "pathToImage",
67
+ "tags": [
68
+ {
69
+ "text": "6.0.0",
70
+ "name": "since"
71
+ }
72
+ ],
73
+ "docs": "The path to the image to set the coordinates to the EXIF metadata.",
74
+ "complexTypes": [],
75
+ "type": "string"
76
+ },
77
+ {
78
+ "name": "lat",
79
+ "tags": [
80
+ {
81
+ "text": "6.0.0",
82
+ "name": "since"
83
+ }
84
+ ],
85
+ "docs": "The latitude of the image coordinates.",
86
+ "complexTypes": [],
87
+ "type": "number"
88
+ },
89
+ {
90
+ "name": "lng",
91
+ "tags": [
92
+ {
93
+ "text": "6.0.0",
94
+ "name": "since"
95
+ }
96
+ ],
97
+ "docs": "The longitude of the image coordinates.",
98
+ "complexTypes": [],
99
+ "type": "number"
100
+ }
101
+ ]
102
+ },
103
+ {
104
+ "name": "GetCoordinatesOptions",
105
+ "slug": "getcoordinatesoptions",
106
+ "docs": "",
107
+ "tags": [],
108
+ "methods": [],
109
+ "properties": [
110
+ {
111
+ "name": "pathToImage",
112
+ "tags": [
113
+ {
114
+ "text": "6.0.0",
115
+ "name": "since"
116
+ }
117
+ ],
118
+ "docs": "The path to the image to get the coordinates from EXIF metadata.",
119
+ "complexTypes": [],
120
+ "type": "string"
121
+ }
122
+ ]
123
+ }
124
+ ],
125
+ "enums": [],
126
+ "typeAliases": [],
127
+ "pluginConfigs": []
128
+ }
@@ -0,0 +1,45 @@
1
+ export interface GetCoordinatesOptions {
2
+ /**
3
+ * The path to the image to get the coordinates from EXIF metadata.
4
+ *
5
+ * @since 6.0.0
6
+ */
7
+ pathToImage: string;
8
+ }
9
+ export interface SetCoordinatesOptions {
10
+ /**
11
+ * The path to the image to set the coordinates to the EXIF metadata.
12
+ *
13
+ * @since 6.0.0
14
+ */
15
+ pathToImage: string;
16
+ /**
17
+ * The latitude of the image coordinates.
18
+ *
19
+ * @since 6.0.0
20
+ */
21
+ lat: number;
22
+ /**
23
+ * The longitude of the image coordinates.
24
+ *
25
+ * @since 6.0.0
26
+ */
27
+ lng: number;
28
+ }
29
+ export interface ExifPlugin {
30
+ /**
31
+ * Set the coordinates to the image EXIF metadata.
32
+ *
33
+ * @since 6.0.0
34
+ */
35
+ setCoordinates(options: SetCoordinatesOptions): Promise<void>;
36
+ /**
37
+ * Get the coordinates from the image EXIF metadata.
38
+ *
39
+ * @since 6.0.0
40
+ */
41
+ getCoordinates(options: GetCoordinatesOptions): Promise<{
42
+ lat: number;
43
+ lng: number;
44
+ } | undefined>;
45
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface GetCoordinatesOptions {\n\n /**\n * The path to the image to get the coordinates from EXIF metadata.\n * \n * @since 6.0.0\n */\n pathToImage: string;\n\n}\n\nexport interface SetCoordinatesOptions {\n\n /**\n * The path to the image to set the coordinates to the EXIF metadata.\n * \n * @since 6.0.0\n */\n pathToImage: string;\n\n /**\n * The latitude of the image coordinates.\n *\n * @since 6.0.0\n */\n lat: number;\n\n /**\n * The longitude of the image coordinates.\n *\n * @since 6.0.0\n */\n lng: number;\n\n}\n\nexport interface ExifPlugin {\n\n /**\n * Set the coordinates to the image EXIF metadata.\n *\n * @since 6.0.0\n */\n setCoordinates(options: SetCoordinatesOptions): Promise<void>;\n\n /**\n * Get the coordinates from the image EXIF metadata.\n *\n * @since 6.0.0\n */\n getCoordinates(options: GetCoordinatesOptions): Promise<{\n lat: number;\n lng: number;\n } | undefined>;\n\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { ExifPlugin } from './definitions';
2
+ declare const Exif: ExifPlugin;
3
+ export * from './definitions';
4
+ export { Exif };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const Exif = registerPlugin('Exif', {
3
+ web: () => import('./web').then(m => new m.ExifWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { Exif };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,IAAI,GAAG,cAAc,CAAa,MAAM,EAAE;IAC9C,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;CACtD,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { ExifPlugin } from './definitions';\n\nconst Exif = registerPlugin<ExifPlugin>('Exif', {\n web: () => import('./web').then(m => new m.ExifWeb()),\n});\n\nexport * from './definitions';\nexport { Exif };\n"]}
@@ -0,0 +1,9 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { GetCoordinatesOptions, SetCoordinatesOptions, ExifPlugin } from './definitions';
3
+ export declare class ExifWeb extends WebPlugin implements ExifPlugin {
4
+ setCoordinates(_options: SetCoordinatesOptions): Promise<void>;
5
+ getCoordinates(_options: GetCoordinatesOptions): Promise<{
6
+ lat: number;
7
+ lng: number;
8
+ } | undefined>;
9
+ }
@@ -0,0 +1,12 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class ExifWeb extends WebPlugin {
3
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
+ async setCoordinates(_options) {
5
+ throw new Error('setCoordinates is not supported on web');
6
+ }
7
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
+ async getCoordinates(_options) {
9
+ throw new Error('getCoordinates is not supported on web');
10
+ }
11
+ }
12
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,OAAQ,SAAQ,SAAS;IAEpC,6DAA6D;IACtD,KAAK,CAAC,cAAc,CAAC,QAA+B;QACzD,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,6DAA6D;IACtD,KAAK,CAAC,cAAc,CAAC,QAA+B;QAIzD,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;CAEF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { GetCoordinatesOptions, SetCoordinatesOptions, ExifPlugin } from './definitions';\n\nexport class ExifWeb extends WebPlugin implements ExifPlugin {\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n public async setCoordinates(_options: SetCoordinatesOptions): Promise<void> {\n throw new Error('setCoordinates is not supported on web');\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n public async getCoordinates(_options: GetCoordinatesOptions): Promise<{\n lat: number;\n lng: number;\n } | undefined> {\n throw new Error('getCoordinates is not supported on web');\n }\n\n}\n"]}
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var core = require('@capacitor/core');
6
+
7
+ const Exif = core.registerPlugin('Exif', {
8
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.ExifWeb()),
9
+ });
10
+
11
+ class ExifWeb extends core.WebPlugin {
12
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
+ async setCoordinates(_options) {
14
+ throw new Error('setCoordinates is not supported on web');
15
+ }
16
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
17
+ async getCoordinates(_options) {
18
+ throw new Error('getCoordinates is not supported on web');
19
+ }
20
+ }
21
+
22
+ var web = /*#__PURE__*/Object.freeze({
23
+ __proto__: null,
24
+ ExifWeb: ExifWeb
25
+ });
26
+
27
+ exports.Exif = Exif;
28
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Exif = registerPlugin('Exif', {\n web: () => import('./web').then(m => new m.ExifWeb()),\n});\nexport * from './definitions';\nexport { Exif };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class ExifWeb extends WebPlugin {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async setCoordinates(_options) {\n throw new Error('setCoordinates is not supported on web');\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async getCoordinates(_options) {\n throw new Error('getCoordinates is not supported on web');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,IAAI,GAAGA,mBAAc,CAAC,MAAM,EAAE;AACpC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;AACzD,CAAC;;ACFM,MAAM,OAAO,SAASC,cAAS,CAAC;AACvC;AACA,IAAI,MAAM,cAAc,CAAC,QAAQ,EAAE;AACnC,QAAQ,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;AAClE,KAAK;AACL;AACA,IAAI,MAAM,cAAc,CAAC,QAAQ,EAAE;AACnC,QAAQ,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;AAClE,KAAK;AACL;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,31 @@
1
+ var capacitorExif = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const Exif = core.registerPlugin('Exif', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.ExifWeb()),
6
+ });
7
+
8
+ class ExifWeb extends core.WebPlugin {
9
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
10
+ async setCoordinates(_options) {
11
+ throw new Error('setCoordinates is not supported on web');
12
+ }
13
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
+ async getCoordinates(_options) {
15
+ throw new Error('getCoordinates is not supported on web');
16
+ }
17
+ }
18
+
19
+ var web = /*#__PURE__*/Object.freeze({
20
+ __proto__: null,
21
+ ExifWeb: ExifWeb
22
+ });
23
+
24
+ exports.Exif = Exif;
25
+
26
+ Object.defineProperty(exports, '__esModule', { value: true });
27
+
28
+ return exports;
29
+
30
+ })({}, capacitorExports);
31
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Exif = registerPlugin('Exif', {\n web: () => import('./web').then(m => new m.ExifWeb()),\n});\nexport * from './definitions';\nexport { Exif };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class ExifWeb extends WebPlugin {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async setCoordinates(_options) {\n throw new Error('setCoordinates is not supported on web');\n }\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n async getCoordinates(_options) {\n throw new Error('getCoordinates is not supported on web');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,IAAI,GAAGA,mBAAc,CAAC,MAAM,EAAE;IACpC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;IACzD,CAAC;;ICFM,MAAM,OAAO,SAASC,cAAS,CAAC;IACvC;IACA,IAAI,MAAM,cAAc,CAAC,QAAQ,EAAE;IACnC,QAAQ,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAClE,KAAK;IACL;IACA,IAAI,MAAM,cAAc,CAAC,QAAQ,EAAE;IACnC,QAAQ,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAClE,KAAK;IACL;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,97 @@
1
+ import Foundation
2
+ import ImageIO
3
+ import MobileCoreServices
4
+ import CoreLocation
5
+
6
+ public enum ImageProcessingError: Error {
7
+ case invalidURL
8
+ case failedToLoadImage
9
+ case failedToCreateDestinationImage
10
+ case failedToSaveImage
11
+ case noGPSData
12
+ }
13
+
14
+ @objc public class Exif: NSObject {
15
+
16
+ func setCoordinates(_ pathToImage: String, _ latitude: Double, _ longitude: Double) throws {
17
+
18
+ // Convert the file path to a URL
19
+ guard let fileURL = URL(string: pathToImage) else {
20
+ throw ImageProcessingError.invalidURL
21
+ }
22
+
23
+ // Create an image source from the URL
24
+ guard let imageSource = CGImageSourceCreateWithURL(fileURL as CFURL, nil) else {
25
+ throw ImageProcessingError.failedToLoadImage
26
+ }
27
+
28
+ // Get the image metadata
29
+ guard let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? [String: Any] else {
30
+ throw ImageProcessingError.failedToLoadImage
31
+ }
32
+
33
+ // print("Original metadata: \(imageProperties)")
34
+
35
+ // Create a mutable copy of the metadata
36
+ var metadata = imageProperties
37
+
38
+ // Modify the GPS metadata
39
+ var gpsData = metadata[kCGImagePropertyGPSDictionary as String] as? [String: Any] ?? [:]
40
+ gpsData[kCGImagePropertyGPSLatitude as String] = abs(latitude)
41
+ gpsData[kCGImagePropertyGPSLatitudeRef as String] = (latitude >= 0.0) ? "N" : "S"
42
+ gpsData[kCGImagePropertyGPSLongitude as String] = abs(longitude)
43
+ gpsData[kCGImagePropertyGPSLongitudeRef as String] = (longitude >= 0.0) ? "E" : "W"
44
+ metadata[kCGImagePropertyGPSDictionary as String] = gpsData
45
+
46
+ // print("Modified metadata: \(metadata)")
47
+
48
+ // Create a destination to write the new image data
49
+ guard let destination = CGImageDestinationCreateWithURL(fileURL as CFURL, kUTTypeJPEG, 1, nil) else {
50
+ throw ImageProcessingError.failedToCreateDestinationImage
51
+ }
52
+
53
+ // Add the image and the updated metadata to the destination
54
+ CGImageDestinationAddImageFromSource(destination, imageSource, 0, metadata as CFDictionary)
55
+
56
+ // Finalize the destination to write the data
57
+ if !CGImageDestinationFinalize(destination) {
58
+ throw ImageProcessingError.failedToSaveImage
59
+ }
60
+
61
+ // print("Successfully saved image with updated metadata")
62
+ }
63
+
64
+ func getCoordinates(filePath: String) throws -> CLLocationCoordinate2D {
65
+
66
+ // Convert the file path to a URL
67
+ guard let fileURL = URL(string: filePath) else {
68
+ throw ImageProcessingError.invalidURL
69
+ }
70
+
71
+ // Create an image source from the URL
72
+ guard let imageSource = CGImageSourceCreateWithURL(fileURL as CFURL, nil) else {
73
+ throw ImageProcessingError.failedToLoadImage
74
+ }
75
+
76
+ // Get the image metadata
77
+ guard let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? [String: Any] else {
78
+ throw ImageProcessingError.failedToLoadImage
79
+ }
80
+
81
+ // Extract the GPS metadata
82
+ guard let gpsData = imageProperties[kCGImagePropertyGPSDictionary as String] as? [String: Any],
83
+ let latitude = gpsData[kCGImagePropertyGPSLatitude as String] as? Double,
84
+ let latitudeRef = gpsData[kCGImagePropertyGPSLatitudeRef as String] as? String,
85
+ let longitude = gpsData[kCGImagePropertyGPSLongitude as String] as? Double,
86
+ let longitudeRef = gpsData[kCGImagePropertyGPSLongitudeRef as String] as? String else {
87
+ throw ImageProcessingError.noGPSData
88
+ }
89
+
90
+ // Calculate the coordinates
91
+ let finalLatitude = (latitudeRef == "N") ? latitude : -latitude
92
+ let finalLongitude = (longitudeRef == "E") ? longitude : -longitude
93
+
94
+ return CLLocationCoordinate2D(latitude: finalLatitude, longitude: finalLongitude)
95
+ }
96
+
97
+ }
@@ -0,0 +1,83 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ /**
5
+ * Please read the Capacitor iOS Plugin Development Guide
6
+ * here: https://capacitorjs.com/docs/plugins/ios
7
+ */
8
+ @objc(ExifPlugin)
9
+ public class ExifPlugin: CAPPlugin, CAPBridgedPlugin {
10
+
11
+ public let identifier = "ExifPlugin"
12
+ public let jsName = "Exif"
13
+ public let pluginMethods: [CAPPluginMethod] = [
14
+ CAPPluginMethod(name: "setCoordinates", returnType: CAPPluginReturnPromise),
15
+ CAPPluginMethod(name: "getCoordinates", returnType: CAPPluginReturnPromise)
16
+ ]
17
+
18
+ // Message constants
19
+ static let INVALID_URL_ERROR = "Invalid URL";
20
+ static let FAILED_TO_LOAD_IMAGE_ERROR = "Failed to load image";
21
+ static let FAILED_TO_CREATE_DESTINATION_IMAGE_ERROR = "Failed to create destination image";
22
+ static let FAILED_TO_SAVE_IMAGE_ERROR = "Failed to save image";
23
+
24
+ private let implementation = Exif()
25
+
26
+ @objc func setCoordinates(_ call: CAPPluginCall) {
27
+
28
+ guard let pathToImage = call.options["pathToImage"] as? String else {
29
+ call.reject("Must provide an pathToImage")
30
+ return
31
+ }
32
+ guard let latitude = call.options["lat"] as? Double else {
33
+ call.reject("Must provide an lat")
34
+ return
35
+ }
36
+ guard let longitude = call.options["lng"] as? Double else {
37
+ call.reject("Must provide an lng")
38
+ return
39
+ }
40
+
41
+ do {
42
+ try implementation.setCoordinates(pathToImage, latitude, longitude)
43
+ call.resolve()
44
+ } catch ImageProcessingError.invalidURL {
45
+ call.reject(ExifPlugin.INVALID_URL_ERROR)
46
+ } catch ImageProcessingError.failedToLoadImage {
47
+ call.reject(ExifPlugin.FAILED_TO_LOAD_IMAGE_ERROR)
48
+ } catch ImageProcessingError.failedToCreateDestinationImage {
49
+ call.reject(ExifPlugin.FAILED_TO_CREATE_DESTINATION_IMAGE_ERROR)
50
+ } catch ImageProcessingError.failedToSaveImage {
51
+ call.reject(ExifPlugin.FAILED_TO_SAVE_IMAGE_ERROR)
52
+ } catch {
53
+ call.reject(error.localizedDescription, nil, error)
54
+ }
55
+
56
+ }
57
+
58
+ @objc func getCoordinates(_ call: CAPPluginCall) {
59
+
60
+ guard let pathToImage = call.options["pathToImage"] as? String else {
61
+ call.reject("Must provide an pathToImage")
62
+ return
63
+ }
64
+
65
+ do {
66
+ let coordinates = try implementation.getCoordinates(filePath: pathToImage)
67
+ call.resolve([
68
+ "lat": coordinates.latitude,
69
+ "lng": coordinates.longitude
70
+ ])
71
+ } catch ImageProcessingError.invalidURL {
72
+ call.reject(ExifPlugin.INVALID_URL_ERROR)
73
+ } catch ImageProcessingError.failedToLoadImage {
74
+ call.reject(ExifPlugin.FAILED_TO_LOAD_IMAGE_ERROR)
75
+ } catch ImageProcessingError.noGPSData {
76
+ call.resolve()
77
+ } catch {
78
+ call.reject(error.localizedDescription, nil, error)
79
+ }
80
+
81
+ }
82
+
83
+ }
@@ -0,0 +1,15 @@
1
+ import XCTest
2
+ @testable import ExifPlugin
3
+
4
+ class ExifTests: XCTestCase {
5
+ func testEcho() {
6
+ // This is an example of a functional test case for a plugin.
7
+ // Use XCTAssert and related functions to verify your tests produce the correct results.
8
+
9
+ let implementation = Exif()
10
+ let value = "Hello, World!"
11
+ let result = implementation.echo(value)
12
+
13
+ XCTAssertEqual(value, result)
14
+ }
15
+ }
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@capacitor-community/exif",
3
+ "version": "6.0.0",
4
+ "description": "This plugin offers utility functions for interacting with image exif metadata",
5
+ "main": "dist/plugin.cjs.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/esm/index.d.ts",
8
+ "unpkg": "dist/plugin.js",
9
+ "files": [
10
+ "android/src/main/",
11
+ "android/build.gradle",
12
+ "dist/",
13
+ "ios/Sources",
14
+ "ios/Tests",
15
+ "Package.swift",
16
+ "CapacitorCommunityExif.podspec"
17
+ ],
18
+ "author": {
19
+ "name": "Alex Ryltsov",
20
+ "email": "ryltsov.alex@gmail.com"
21
+ },
22
+ "contributors": [
23
+ {
24
+ "name": "Alex Ryltsov",
25
+ "email": "ryltsov.alex@gmail.com"
26
+ }
27
+ ],
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/capacitor-community/exif.git"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/capacitor-community/exif/issues"
35
+ },
36
+ "keywords": [
37
+ "capacitor",
38
+ "plugin",
39
+ "native"
40
+ ],
41
+ "scripts": {
42
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
43
+ "verify:ios": "xcodebuild -scheme CapacitorCommunityExif -destination generic/platform=iOS",
44
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
45
+ "verify:web": "npm run build",
46
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
47
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
48
+ "eslint": "eslint . --ext ts",
49
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
50
+ "swiftlint": "node-swiftlint",
51
+ "docgen": "docgen --api ExifPlugin --output-readme README.md --output-json dist/docs.json",
52
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
53
+ "clean": "rimraf ./dist",
54
+ "watch": "tsc --watch",
55
+ "prepublishOnly": "npm run build"
56
+ },
57
+ "devDependencies": {
58
+ "@capacitor/android": "^6.0.0",
59
+ "@capacitor/core": "^6.0.0",
60
+ "@capacitor/docgen": "^0.2.2",
61
+ "@capacitor/ios": "^6.0.0",
62
+ "@ionic/eslint-config": "^0.4.0",
63
+ "@ionic/prettier-config": "^1.0.1",
64
+ "@ionic/swiftlint-config": "^1.1.2",
65
+ "eslint": "^8.57.0",
66
+ "prettier": "~2.3.0",
67
+ "prettier-plugin-java": "~1.0.2",
68
+ "rimraf": "^3.0.2",
69
+ "rollup": "^2.32.0",
70
+ "swiftlint": "^1.0.1",
71
+ "typescript": "~4.1.5"
72
+ },
73
+ "peerDependencies": {
74
+ "@capacitor/core": "^6.0.0"
75
+ },
76
+ "prettier": "@ionic/prettier-config",
77
+ "swiftlint": "@ionic/swiftlint-config",
78
+ "eslintConfig": {
79
+ "extends": "@ionic/eslint-config/recommended"
80
+ },
81
+ "capacitor": {
82
+ "ios": {
83
+ "src": "ios"
84
+ },
85
+ "android": {
86
+ "src": "android"
87
+ }
88
+ },
89
+ "engines": {
90
+ "node": ">=16.0.0",
91
+ "npm": ">=8.0.0"
92
+ }
93
+ }