@capgo/camera-preview 7.16.5 → 7.18.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.
- package/README.md +10 -8
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraPreview.java +15 -1
- package/android/src/main/java/app/capgo/capacitor/camera/preview/CameraXView.java +190 -3
- package/dist/docs.json +32 -0
- package/dist/esm/definitions.d.ts +13 -0
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/CapgoCameraPreviewPlugin/CameraController.swift +220 -1
- package/ios/Sources/CapgoCameraPreviewPlugin/Plugin.swift +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1028,14 +1028,16 @@ Represents EXIF data extracted from an image.
|
|
|
1028
1028
|
|
|
1029
1029
|
Defines the options for capturing a picture.
|
|
1030
1030
|
|
|
1031
|
-
| Prop | Type | Description | Default | Since
|
|
1032
|
-
| ---------------------- | ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
|
|
1033
|
-
| **`height`** | <code>number</code> | The maximum height of the picture in pixels. The image will be resized to fit within this height while maintaining aspect ratio. If not specified the captured image will match the preview's visible area. | |
|
|
1034
|
-
| **`width`** | <code>number</code> | The maximum width of the picture in pixels. The image will be resized to fit within this width while maintaining aspect ratio. If not specified the captured image will match the preview's visible area. | |
|
|
1035
|
-
| **`quality`** | <code>number</code> | The quality of the captured image, from 0 to 100. Does not apply to `png` format. | <code>85</code> |
|
|
1036
|
-
| **`format`** | <code><a href="#pictureformat">PictureFormat</a></code> | The format of the captured image. | <code>"jpeg"</code> |
|
|
1037
|
-
| **`saveToGallery`** | <code>boolean</code> | If true, the captured image will be saved to the user's gallery. | <code>false</code> | 7.5.0
|
|
1038
|
-
| **`withExifLocation`** | <code>boolean</code> | If true, the plugin will attempt to add GPS location data to the image's EXIF metadata. This may prompt the user for location permissions. | <code>false</code> | 7.6.0
|
|
1031
|
+
| Prop | Type | Description | Default | Since |
|
|
1032
|
+
| ---------------------- | ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | ------ |
|
|
1033
|
+
| **`height`** | <code>number</code> | The maximum height of the picture in pixels. The image will be resized to fit within this height while maintaining aspect ratio. If not specified the captured image will match the preview's visible area. | | |
|
|
1034
|
+
| **`width`** | <code>number</code> | The maximum width of the picture in pixels. The image will be resized to fit within this width while maintaining aspect ratio. If not specified the captured image will match the preview's visible area. | | |
|
|
1035
|
+
| **`quality`** | <code>number</code> | The quality of the captured image, from 0 to 100. Does not apply to `png` format. | <code>85</code> | |
|
|
1036
|
+
| **`format`** | <code><a href="#pictureformat">PictureFormat</a></code> | The format of the captured image. | <code>"jpeg"</code> | |
|
|
1037
|
+
| **`saveToGallery`** | <code>boolean</code> | If true, the captured image will be saved to the user's gallery. | <code>false</code> | 7.5.0 |
|
|
1038
|
+
| **`withExifLocation`** | <code>boolean</code> | If true, the plugin will attempt to add GPS location data to the image's EXIF metadata. This may prompt the user for location permissions. | <code>false</code> | 7.6.0 |
|
|
1039
|
+
| **`embedTimestamp`** | <code>boolean</code> | If true, the plugin will embed a timestamp in the top-right corner of the image. | <code>false</code> | 7.17.0 |
|
|
1040
|
+
| **`embedLocation`** | <code>boolean</code> | If true, the plugin will embed the current location in the top-right corner of the image. Requires `withExifLocation` to be enabled. | <code>false</code> | 7.18.0 |
|
|
1039
1041
|
|
|
1040
1042
|
|
|
1041
1043
|
#### CameraSampleOptions
|
|
@@ -369,8 +369,22 @@ public class CameraPreview
|
|
|
369
369
|
);
|
|
370
370
|
Integer width = call.getInt("width");
|
|
371
371
|
Integer height = call.getInt("height");
|
|
372
|
+
final boolean embedTimestamp = Boolean.TRUE.equals(
|
|
373
|
+
call.getBoolean("embedTimestamp")
|
|
374
|
+
);
|
|
375
|
+
final boolean embedLocation = Boolean.TRUE.equals(
|
|
376
|
+
call.getBoolean("embedLocation")
|
|
377
|
+
);
|
|
372
378
|
|
|
373
|
-
cameraXView.capturePhoto(
|
|
379
|
+
cameraXView.capturePhoto(
|
|
380
|
+
quality,
|
|
381
|
+
saveToGallery,
|
|
382
|
+
width,
|
|
383
|
+
height,
|
|
384
|
+
location,
|
|
385
|
+
embedTimestamp,
|
|
386
|
+
embedLocation
|
|
387
|
+
);
|
|
374
388
|
}
|
|
375
389
|
|
|
376
390
|
@PluginMethod
|
|
@@ -6,9 +6,12 @@ import android.content.pm.PackageManager;
|
|
|
6
6
|
import android.content.res.Configuration;
|
|
7
7
|
import android.graphics.Bitmap;
|
|
8
8
|
import android.graphics.BitmapFactory;
|
|
9
|
+
import android.graphics.Canvas;
|
|
9
10
|
import android.graphics.Color;
|
|
10
11
|
import android.graphics.Matrix;
|
|
12
|
+
import android.graphics.Paint;
|
|
11
13
|
import android.graphics.Rect;
|
|
14
|
+
import android.graphics.Typeface;
|
|
12
15
|
import android.graphics.drawable.GradientDrawable;
|
|
13
16
|
import android.hardware.camera2.CameraAccessException;
|
|
14
17
|
import android.hardware.camera2.CameraCharacteristics;
|
|
@@ -86,6 +89,7 @@ import java.text.SimpleDateFormat;
|
|
|
86
89
|
import java.util.ArrayList;
|
|
87
90
|
import java.util.Arrays;
|
|
88
91
|
import java.util.Collections;
|
|
92
|
+
import java.util.Date;
|
|
89
93
|
import java.util.List;
|
|
90
94
|
import java.util.Locale;
|
|
91
95
|
import java.util.Objects;
|
|
@@ -1164,7 +1168,9 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1164
1168
|
final boolean saveToGallery,
|
|
1165
1169
|
Integer width,
|
|
1166
1170
|
Integer height,
|
|
1167
|
-
Location location
|
|
1171
|
+
Location location,
|
|
1172
|
+
final boolean embedTimestamp,
|
|
1173
|
+
final boolean embedLocation
|
|
1168
1174
|
) {
|
|
1169
1175
|
// Prevent capture if a stop is pending
|
|
1170
1176
|
if (IsOperationRunning("capturePhoto")) {
|
|
@@ -1173,12 +1179,18 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1173
1179
|
}
|
|
1174
1180
|
Log.d(
|
|
1175
1181
|
TAG,
|
|
1176
|
-
"capturePhoto: Starting photo capture with
|
|
1182
|
+
"capturePhoto: Starting photo capture with: " +
|
|
1177
1183
|
quality +
|
|
1178
1184
|
", width: " +
|
|
1179
1185
|
width +
|
|
1180
1186
|
", height: " +
|
|
1181
|
-
height
|
|
1187
|
+
height +
|
|
1188
|
+
", saveToGallery: " +
|
|
1189
|
+
saveToGallery +
|
|
1190
|
+
", embedTimestamp: " +
|
|
1191
|
+
embedTimestamp +
|
|
1192
|
+
", embedLocation: " +
|
|
1193
|
+
embedLocation
|
|
1182
1194
|
);
|
|
1183
1195
|
|
|
1184
1196
|
if (imageCapture == null) {
|
|
@@ -1253,6 +1265,14 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1253
1265
|
width,
|
|
1254
1266
|
height
|
|
1255
1267
|
);
|
|
1268
|
+
if (embedTimestamp || embedLocation) {
|
|
1269
|
+
resizedBitmap = drawTimestampAndLocationOntoBitmap(
|
|
1270
|
+
resizedBitmap,
|
|
1271
|
+
exifInterface,
|
|
1272
|
+
embedTimestamp,
|
|
1273
|
+
embedLocation
|
|
1274
|
+
);
|
|
1275
|
+
}
|
|
1256
1276
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
|
1257
1277
|
resizedBitmap.compress(
|
|
1258
1278
|
Bitmap.CompressFormat.JPEG,
|
|
@@ -1287,6 +1307,14 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1287
1307
|
exifInterface
|
|
1288
1308
|
);
|
|
1289
1309
|
Bitmap previewCropped = cropBitmapToMatchPreview(originalBitmap);
|
|
1310
|
+
if (embedTimestamp || embedLocation) {
|
|
1311
|
+
previewCropped = drawTimestampAndLocationOntoBitmap(
|
|
1312
|
+
previewCropped,
|
|
1313
|
+
exifInterface,
|
|
1314
|
+
embedTimestamp,
|
|
1315
|
+
embedLocation
|
|
1316
|
+
);
|
|
1317
|
+
}
|
|
1290
1318
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
|
1291
1319
|
previewCropped.compress(
|
|
1292
1320
|
Bitmap.CompressFormat.JPEG,
|
|
@@ -1385,6 +1413,165 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1385
1413
|
);
|
|
1386
1414
|
}
|
|
1387
1415
|
|
|
1416
|
+
private Bitmap drawTimestampAndLocationOntoBitmap(
|
|
1417
|
+
Bitmap src,
|
|
1418
|
+
ExifInterface exif,
|
|
1419
|
+
boolean embedTimestamp,
|
|
1420
|
+
boolean embedLocation
|
|
1421
|
+
) {
|
|
1422
|
+
if (src == null) return null;
|
|
1423
|
+
|
|
1424
|
+
// Build strings (null-safe)
|
|
1425
|
+
final String when = embedTimestamp
|
|
1426
|
+
? buildTimestampStringFromExif(exif)
|
|
1427
|
+
: null;
|
|
1428
|
+
final String where =
|
|
1429
|
+
(embedLocation ? buildLocationStringFromExif(exif) : null);
|
|
1430
|
+
|
|
1431
|
+
// Nothing to draw?
|
|
1432
|
+
if (
|
|
1433
|
+
(when == null || when.isEmpty()) && (where == null || where.isEmpty())
|
|
1434
|
+
) {
|
|
1435
|
+
Log.d(
|
|
1436
|
+
TAG,
|
|
1437
|
+
"capturePhoto:... embedTimestamp: " +
|
|
1438
|
+
embedTimestamp +
|
|
1439
|
+
", embedLocation: " +
|
|
1440
|
+
embedLocation
|
|
1441
|
+
);
|
|
1442
|
+
Log.d(TAG, "capturePhoto: nothing to draw");
|
|
1443
|
+
return src;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
final Bitmap bmp = src.isMutable()
|
|
1447
|
+
? src
|
|
1448
|
+
: src.copy(Bitmap.Config.ARGB_8888, true);
|
|
1449
|
+
final Canvas canvas = new Canvas(bmp);
|
|
1450
|
+
|
|
1451
|
+
// ---- Visual constants (match timestamp style) ----
|
|
1452
|
+
final float fontPx = Math.max(10f, bmp.getWidth() * 0.035f); // ~3.5% of width
|
|
1453
|
+
final float paddingH = 16f; // horizontal inner padding
|
|
1454
|
+
final float paddingV = 10f; // vertical inner padding
|
|
1455
|
+
final float margin = 12f; // margin from image edges
|
|
1456
|
+
final float gap = 8f; // vertical gap between stacked pills
|
|
1457
|
+
final float corner = 10f; // corner radius
|
|
1458
|
+
final int bgColor = Color.argb(56, 31, 31, 31); // ~iOS gray at ~22% alpha
|
|
1459
|
+
|
|
1460
|
+
// Text paint
|
|
1461
|
+
final Paint text = new Paint(
|
|
1462
|
+
Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.LINEAR_TEXT_FLAG
|
|
1463
|
+
);
|
|
1464
|
+
text.setColor(Color.WHITE);
|
|
1465
|
+
text.setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
|
|
1466
|
+
text.setTextSize(fontPx);
|
|
1467
|
+
text.setTextAlign(Paint.Align.LEFT);
|
|
1468
|
+
text.setDither(true);
|
|
1469
|
+
text.setFilterBitmap(true);
|
|
1470
|
+
text.setHinting(Paint.HINTING_ON);
|
|
1471
|
+
final Paint.FontMetrics fm = text.getFontMetrics();
|
|
1472
|
+
final float lineHeight = fm.descent - fm.ascent;
|
|
1473
|
+
|
|
1474
|
+
// Background paint
|
|
1475
|
+
final Paint bg = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
1476
|
+
bg.setColor(bgColor);
|
|
1477
|
+
bg.setStyle(Paint.Style.FILL);
|
|
1478
|
+
bg.setShadowLayer(6f, 0f, 2f, Color.argb(64, 0, 0, 0));
|
|
1479
|
+
|
|
1480
|
+
float nextTop = margin;
|
|
1481
|
+
|
|
1482
|
+
// Helper to draw a pill aligned to the top-right, returns the bottom Y used
|
|
1483
|
+
java.util.function.BiFunction<String, Float, Float> drawPill = (
|
|
1484
|
+
label,
|
|
1485
|
+
top
|
|
1486
|
+
) -> {
|
|
1487
|
+
if (label == null || label.isEmpty()) return top;
|
|
1488
|
+
float textW = text.measureText(label);
|
|
1489
|
+
float bgW = textW + paddingH * 2f;
|
|
1490
|
+
float bgH = lineHeight + paddingV * 2f;
|
|
1491
|
+
|
|
1492
|
+
float left = Math.max(0, bmp.getWidth() - bgW - margin);
|
|
1493
|
+
float right = left + bgW;
|
|
1494
|
+
float bottom = top + bgH;
|
|
1495
|
+
|
|
1496
|
+
// Background
|
|
1497
|
+
canvas.drawRoundRect(left, top, right, bottom, corner, corner, bg);
|
|
1498
|
+
|
|
1499
|
+
// Text baseline
|
|
1500
|
+
float textX = left + paddingH;
|
|
1501
|
+
float textY = top + paddingV - fm.ascent; // convert top-left to baseline
|
|
1502
|
+
canvas.drawText(label, textX, textY, text);
|
|
1503
|
+
|
|
1504
|
+
return bottom;
|
|
1505
|
+
};
|
|
1506
|
+
|
|
1507
|
+
// 1) Timestamp (if any)
|
|
1508
|
+
if (when != null && !when.isEmpty()) {
|
|
1509
|
+
nextTop = drawPill.apply(when, nextTop);
|
|
1510
|
+
// add gap below
|
|
1511
|
+
nextTop += gap;
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
// 2) Location (if any)
|
|
1515
|
+
if (where != null && !where.isEmpty()) {
|
|
1516
|
+
// If there was no timestamp drawn, we still start at top margin.
|
|
1517
|
+
// If there was, we use the accumulated nextTop (= bottom + gap).
|
|
1518
|
+
drawPill.apply(
|
|
1519
|
+
where,
|
|
1520
|
+
(when != null && !when.isEmpty()) ? nextTop : margin
|
|
1521
|
+
);
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
return bmp;
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
/** Build "yyyy-MM-dd HH:mm:ss" from EXIF, fallback to now. */
|
|
1528
|
+
private String buildTimestampStringFromExif(ExifInterface exif) {
|
|
1529
|
+
final String out = "yyyy-MM-dd HH:mm:ss";
|
|
1530
|
+
try {
|
|
1531
|
+
if (exif != null) {
|
|
1532
|
+
String exifDate = exif.getAttribute(
|
|
1533
|
+
ExifInterface.TAG_DATETIME_ORIGINAL
|
|
1534
|
+
);
|
|
1535
|
+
if (exifDate == null || exifDate.trim().isEmpty()) {
|
|
1536
|
+
exifDate = exif.getAttribute(ExifInterface.TAG_DATETIME);
|
|
1537
|
+
}
|
|
1538
|
+
if (exifDate != null && !exifDate.trim().isEmpty()) {
|
|
1539
|
+
java.text.SimpleDateFormat in = new java.text.SimpleDateFormat(
|
|
1540
|
+
"yyyy:MM:dd HH:mm:ss",
|
|
1541
|
+
java.util.Locale.US
|
|
1542
|
+
);
|
|
1543
|
+
java.util.Date d = in.parse(exifDate);
|
|
1544
|
+
if (d != null) {
|
|
1545
|
+
return new java.text.SimpleDateFormat(
|
|
1546
|
+
out,
|
|
1547
|
+
java.util.Locale.getDefault()
|
|
1548
|
+
).format(d);
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
} catch (Throwable ignored) {}
|
|
1553
|
+
// Fallback to "now" if EXIF missing/invalid
|
|
1554
|
+
return new java.text.SimpleDateFormat(
|
|
1555
|
+
out,
|
|
1556
|
+
java.util.Locale.getDefault()
|
|
1557
|
+
).format(new java.util.Date());
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
/** Build "lat, lon" from EXIF GPS. Returns null if absent (so caller can skip). */
|
|
1561
|
+
private String buildLocationStringFromExif(ExifInterface exif) {
|
|
1562
|
+
if (exif == null) return null;
|
|
1563
|
+
try {
|
|
1564
|
+
float[] latLong = new float[2];
|
|
1565
|
+
if (exif.getLatLong(latLong)) {
|
|
1566
|
+
// Keep a compact but readable precision (5 decimals ≈ ~1 m–10 m)
|
|
1567
|
+
String lat = String.format(java.util.Locale.US, "%.5f", latLong[0]);
|
|
1568
|
+
String lon = String.format(java.util.Locale.US, "%.5f", latLong[1]);
|
|
1569
|
+
return lat + ", " + lon;
|
|
1570
|
+
}
|
|
1571
|
+
} catch (Throwable ignored) {}
|
|
1572
|
+
return null; // No EXIF GPS → skip
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1388
1575
|
private int exifToDegrees(int exifOrientation) {
|
|
1389
1576
|
switch (exifOrientation) {
|
|
1390
1577
|
case ExifInterface.ORIENTATION_ROTATE_90:
|
package/dist/docs.json
CHANGED
|
@@ -1428,6 +1428,38 @@
|
|
|
1428
1428
|
"docs": "If true, the plugin will attempt to add GPS location data to the image's EXIF metadata.\nThis may prompt the user for location permissions.",
|
|
1429
1429
|
"complexTypes": [],
|
|
1430
1430
|
"type": "boolean | undefined"
|
|
1431
|
+
},
|
|
1432
|
+
{
|
|
1433
|
+
"name": "embedTimestamp",
|
|
1434
|
+
"tags": [
|
|
1435
|
+
{
|
|
1436
|
+
"text": "false",
|
|
1437
|
+
"name": "default"
|
|
1438
|
+
},
|
|
1439
|
+
{
|
|
1440
|
+
"text": "7.17.0",
|
|
1441
|
+
"name": "since"
|
|
1442
|
+
}
|
|
1443
|
+
],
|
|
1444
|
+
"docs": "If true, the plugin will embed a timestamp in the top-right corner of the image.",
|
|
1445
|
+
"complexTypes": [],
|
|
1446
|
+
"type": "boolean | undefined"
|
|
1447
|
+
},
|
|
1448
|
+
{
|
|
1449
|
+
"name": "embedLocation",
|
|
1450
|
+
"tags": [
|
|
1451
|
+
{
|
|
1452
|
+
"text": "false",
|
|
1453
|
+
"name": "default"
|
|
1454
|
+
},
|
|
1455
|
+
{
|
|
1456
|
+
"text": "7.18.0",
|
|
1457
|
+
"name": "since"
|
|
1458
|
+
}
|
|
1459
|
+
],
|
|
1460
|
+
"docs": "If true, the plugin will embed the current location in the top-right corner of the image.\nRequires `withExifLocation` to be enabled.",
|
|
1461
|
+
"complexTypes": [],
|
|
1462
|
+
"type": "boolean | undefined"
|
|
1431
1463
|
}
|
|
1432
1464
|
]
|
|
1433
1465
|
},
|
|
@@ -238,6 +238,19 @@ export interface CameraPreviewPictureOptions {
|
|
|
238
238
|
* @since 7.6.0
|
|
239
239
|
*/
|
|
240
240
|
withExifLocation?: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* If true, the plugin will embed a timestamp in the top-right corner of the image.
|
|
243
|
+
* @default false
|
|
244
|
+
* @since 7.17.0
|
|
245
|
+
*/
|
|
246
|
+
embedTimestamp?: boolean;
|
|
247
|
+
/**
|
|
248
|
+
* If true, the plugin will embed the current location in the top-right corner of the image.
|
|
249
|
+
* Requires `withExifLocation` to be enabled.
|
|
250
|
+
* @default false
|
|
251
|
+
* @since 7.18.0
|
|
252
|
+
*/
|
|
253
|
+
embedLocation?: boolean;
|
|
241
254
|
}
|
|
242
255
|
/** Represents EXIF data extracted from an image. */
|
|
243
256
|
export interface ExifData {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAUA,MAAM,CAAN,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,sCAAwB,CAAA;IACxB,sCAAwB,CAAA;IACxB,qCAAuB,CAAA;IACvB,sCAAwB,CAAA;IACxB,2BAAa,CAAA;IACb,oCAAsB,CAAA;IACtB,+BAAiB,CAAA;AACnB,CAAC,EARW,UAAU,KAAV,UAAU,QAQrB","sourcesContent":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport type CameraPosition = \"rear\" | \"front\";\n\nexport type FlashMode = CameraPreviewFlashMode;\n\nexport type GridMode = \"none\" | \"3x3\" | \"4x4\";\n\nexport type CameraPositioning = \"center\" | \"top\" | \"bottom\";\n\nexport enum DeviceType {\n ULTRA_WIDE = \"ultraWide\",\n WIDE_ANGLE = \"wideAngle\",\n TELEPHOTO = \"telephoto\",\n TRUE_DEPTH = \"trueDepth\",\n DUAL = \"dual\",\n DUAL_WIDE = \"dualWide\",\n TRIPLE = \"triple\",\n}\n\n/**\n * Represents a single camera lens on a device. A {@link CameraDevice} can have multiple lenses.\n */\nexport interface CameraLens {\n /** A human-readable name for the lens, e.g., \"Ultra-Wide\". */\n label: string;\n /** The type of the camera lens. */\n deviceType: DeviceType;\n /** The focal length of the lens in millimeters. */\n focalLength: number;\n /** The base zoom factor for this lens (e.g., 0.5 for ultra-wide, 1.0 for wide). */\n baseZoomRatio: number;\n /** The minimum zoom factor supported by this specific lens. */\n minZoom: number;\n /** The maximum zoom factor supported by this specific lens. */\n maxZoom: number;\n}\n\n/**\n * Represents a physical camera on the device (e.g., the front-facing camera).\n */\nexport interface CameraDevice {\n /** A unique identifier for the camera device. */\n deviceId: string;\n /** A human-readable name for the camera device. */\n label: string;\n /** The physical position of the camera on the device. */\n position: CameraPosition;\n /** A list of all available lenses for this camera device. */\n lenses: CameraLens[];\n /** The overall minimum zoom factor available across all lenses on this device. */\n minZoom: number;\n /** The overall maximum zoom factor available across all lenses on this device. */\n maxZoom: number;\n /** Identifies whether the device is a logical camera (composed of multiple physical lenses). */\n isLogical: boolean;\n}\n\n/**\n * Represents the detailed information of the currently active lens.\n */\nexport interface LensInfo {\n /** The focal length of the active lens in millimeters. */\n focalLength: number;\n /** The device type of the active lens. */\n deviceType: DeviceType;\n /** The base zoom ratio of the active lens (e.g., 0.5x, 1.0x). */\n baseZoomRatio: number;\n /** The current digital zoom factor applied on top of the base zoom. */\n digitalZoom: number;\n}\n\n/**\n * Defines the configuration options for starting the camera preview.\n */\nexport interface CameraPreviewOptions {\n /**\n * The parent element to attach the video preview to.\n * @platform web\n */\n parent?: string;\n /**\n * A CSS class name to add to the preview element.\n * @platform web\n */\n className?: string;\n /**\n * The width of the preview in pixels. Defaults to the screen width.\n * @platform android, ios, web\n */\n width?: number;\n /**\n * The height of the preview in pixels. Defaults to the screen height.\n * @platform android, ios, web\n */\n height?: number;\n /**\n * The horizontal origin of the preview, in pixels.\n * @platform android, ios\n */\n x?: number;\n /**\n * The vertical origin of the preview, in pixels.\n * @platform android, ios\n */\n y?: number;\n /**\n * The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'.\n * Cannot be set if width or height is provided, otherwise the call will be rejected.\n * Use setPreviewSize to adjust size after starting.\n *\n * @since 2.0.0\n */\n aspectRatio?: \"4:3\" | \"16:9\";\n /**\n * The grid overlay to display on the camera preview.\n * @default \"none\"\n * @since 2.1.0\n */\n gridMode?: GridMode;\n /**\n * Adjusts the y-position to account for safe areas (e.g., notches).\n * @platform ios\n * @default false\n */\n includeSafeAreaInsets?: boolean;\n /**\n * If true, places the preview behind the webview.\n * @platform android\n * @default true\n */\n toBack?: boolean;\n /**\n * Bottom padding for the preview, in pixels.\n * @platform android, ios\n */\n paddingBottom?: number;\n /**\n * Whether to rotate the preview when the device orientation changes.\n * @platform ios\n * @default true\n */\n rotateWhenOrientationChanged?: boolean;\n /**\n * The camera to use.\n * @default \"rear\"\n */\n position?: CameraPosition | string;\n /**\n * If true, saves the captured image to a file and returns the file path.\n * If false, returns a base64 encoded string.\n * @default false\n */\n storeToFile?: boolean;\n /**\n * If true, prevents the plugin from rotating the image based on EXIF data.\n * @platform android\n * @default false\n */\n disableExifHeaderStripping?: boolean;\n /**\n * If true, disables the audio stream, preventing audio permission requests.\n * @default true\n */\n disableAudio?: boolean;\n /**\n * If true, locks the device orientation while the camera is active.\n * @platform android\n * @default false\n */\n lockAndroidOrientation?: boolean;\n /**\n * If true, allows the camera preview's opacity to be changed.\n * @platform android, web\n * @default false\n */\n enableOpacity?: boolean;\n\n /**\n * If true, disables the visual focus indicator when tapping to focus.\n * @platform android, ios\n * @default false\n */\n disableFocusIndicator?: boolean;\n /**\n * The `deviceId` of the camera to use. If provided, `position` is ignored.\n * @platform ios\n */\n deviceId?: string;\n /**\n * The initial zoom level when starting the camera preview.\n * If the requested zoom level is not available, the native plugin will reject.\n * @default 1.0\n * @platform android, ios\n * @since 2.2.0\n */\n initialZoomLevel?: number;\n /**\n * The vertical positioning of the camera preview.\n * @default \"center\"\n * @platform android, ios, web\n * @since 2.3.0\n */\n positioning?: CameraPositioning;\n /**\n * If true, enables video capture capabilities when the camera starts.\n * @default false\n * @platform android\n * @since 7.11.0\n */\n enableVideoMode?: boolean;\n}\n\n/**\n * Defines the options for capturing a picture.\n */\nexport interface CameraPreviewPictureOptions {\n /**\n * The maximum height of the picture in pixels. The image will be resized to fit within this height while maintaining aspect ratio.\n * If not specified the captured image will match the preview's visible area.\n */\n height?: number;\n /**\n * The maximum width of the picture in pixels. The image will be resized to fit within this width while maintaining aspect ratio.\n * If not specified the captured image will match the preview's visible area.\n */\n width?: number;\n /**\n * The quality of the captured image, from 0 to 100.\n * Does not apply to `png` format.\n * @default 85\n */\n quality?: number;\n /**\n * The format of the captured image.\n * @default \"jpeg\"\n */\n format?: PictureFormat;\n /**\n * If true, the captured image will be saved to the user's gallery.\n * @default false\n * @since 7.5.0\n */\n saveToGallery?: boolean;\n /**\n * If true, the plugin will attempt to add GPS location data to the image's EXIF metadata.\n * This may prompt the user for location permissions.\n * @default false\n * @since 7.6.0\n */\n withExifLocation?: boolean;\n}\n\n/** Represents EXIF data extracted from an image. */\nexport interface ExifData {\n [key: string]: any;\n}\n\nexport type PictureFormat = \"jpeg\" | \"png\";\n\n/** Defines a standard picture size with width and height. */\nexport interface PictureSize {\n /** The width of the picture in pixels. */\n width: number;\n /** The height of the picture in pixels. */\n height: number;\n}\n\n/** Represents the supported picture sizes for a camera facing a certain direction. */\nexport interface SupportedPictureSizes {\n /** The camera direction (\"front\" or \"rear\"). */\n facing: string;\n /** A list of supported picture sizes for this camera. */\n supportedPictureSizes: PictureSize[];\n}\n\n/**\n * Defines the options for capturing a sample frame from the camera preview.\n */\nexport interface CameraSampleOptions {\n /**\n * The quality of the captured sample, from 0 to 100.\n * @default 85\n */\n quality?: number;\n}\n\n/**\n * The available flash modes for the camera.\n * 'torch' is a continuous light mode.\n */\nexport type CameraPreviewFlashMode = \"off\" | \"on\" | \"auto\" | \"torch\";\n\n/** Reusable exposure mode type for cross-platform support. */\nexport type ExposureMode = \"AUTO\" | \"LOCK\" | \"CONTINUOUS\" | \"CUSTOM\";\n\n/**\n * Defines the options for setting the camera preview's opacity.\n */\nexport interface CameraOpacityOptions {\n /**\n * The opacity percentage, from 0.0 (fully transparent) to 1.0 (fully opaque).\n * @default 1.0\n */\n opacity?: number;\n}\n\n/**\n * Represents safe area insets for devices.\n * Android: Values are expressed in logical pixels (dp) to match JS layout units.\n * iOS: Values are expressed in physical pixels and exclude status bar.\n */\nexport interface SafeAreaInsets {\n /** Current device orientation (1 = portrait, 2 = landscape, 0 = unknown). */\n orientation: number;\n /**\n * Orientation-aware notch/camera cutout inset (excluding status bar).\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch at side).\n * Android: Value in dp, iOS: Value in pixels (status bar excluded).\n */\n top: number;\n}\n\n/**\n * Canonical device orientation values across platforms.\n */\nexport type DeviceOrientation =\n | \"portrait\"\n | \"landscape-left\"\n | \"landscape-right\"\n | \"portrait-upside-down\"\n | \"unknown\";\n\n/**\n * The main interface for the CameraPreview plugin.\n */\nexport interface CameraPreviewPlugin {\n /**\n * Starts the camera preview.\n *\n * @param {CameraPreviewOptions} options - The configuration for the camera preview.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the preview dimensions.\n * @since 0.0.1\n */\n start(options: CameraPreviewOptions): Promise<{\n /** The width of the preview in pixels. */\n width: number;\n /** The height of the preview in pixels. */\n height: number;\n /** The horizontal origin of the preview, in pixels. */\n x: number;\n /** The vertical origin of the preview, in pixels. */\n y: number;\n }>;\n\n /**\n * Stops the camera preview.\n *\n * @returns {Promise<void>} A promise that resolves when the camera preview is stopped.\n * @since 0.0.1\n */\n stop(): Promise<void>;\n\n /**\n * Captures a picture from the camera.\n *\n * If `storeToFile` was set to `true` when starting the preview, the returned\n * `value` will be an absolute file path on the device instead of a base64 string. Use getBase64FromFilePath to get the base64 string from the file path.\n *\n * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.\n * @returns {Promise<{ value: string; exif: ExifData }>} Resolves with:\n * - `value`: base64 string, or file path if `storeToFile` is true\n * - `exif`: extracted EXIF metadata when available\n * @since 0.0.1\n */\n capture(\n options: CameraPreviewPictureOptions,\n ): Promise<{ value: string; exif: ExifData }>;\n\n /**\n * Captures a single frame from the camera preview stream.\n *\n * @param {CameraSampleOptions} options - The options for capturing the sample.\n * @returns {Promise<{ value: string }>} A promise that resolves with the sample image as a base64 encoded string.\n * @since 0.0.1\n */\n captureSample(options: CameraSampleOptions): Promise<{ value: string }>;\n\n /**\n * Gets the flash modes supported by the active camera.\n *\n * @returns {Promise<{ result: CameraPreviewFlashMode[] }>} A promise that resolves with an array of supported flash modes.\n * @since 0.0.1\n */\n getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }>;\n\n /**\n * Set the aspect ratio of the camera preview.\n *\n * @param {{ aspectRatio: '4:3' | '16:9'; x?: number; y?: number }} options - The desired aspect ratio and optional position.\n * - aspectRatio: The desired aspect ratio ('4:3' or '16:9')\n * - x: Optional x coordinate for positioning. If not provided, view will be auto-centered horizontally.\n * - y: Optional y coordinate for positioning. If not provided, view will be auto-centered vertically.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.5.0\n * @platform android, ios\n */\n setAspectRatio(options: {\n aspectRatio: \"4:3\" | \"16:9\";\n x?: number;\n y?: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Gets the current aspect ratio of the camera preview.\n *\n * @returns {Promise<{ aspectRatio: '4:3' | '16:9' }>} A promise that resolves with the current aspect ratio.\n * @since 7.5.0\n * @platform android, ios\n */\n getAspectRatio(): Promise<{ aspectRatio: \"4:3\" | \"16:9\" }>;\n\n /**\n * Sets the grid mode of the camera preview overlay.\n *\n * @param {{ gridMode: GridMode }} options - The desired grid mode ('none', '3x3', or '4x4').\n * @returns {Promise<void>} A promise that resolves when the grid mode is set.\n * @since 8.0.0\n */\n setGridMode(options: { gridMode: GridMode }): Promise<void>;\n\n /**\n * Gets the current grid mode of the camera preview overlay.\n *\n * @returns {Promise<{ gridMode: GridMode }>} A promise that resolves with the current grid mode.\n * @since 8.0.0\n */\n getGridMode(): Promise<{ gridMode: GridMode }>;\n\n /**\n * Gets the horizontal field of view (FoV) for the active camera.\n * Note: This can be an estimate on some devices.\n *\n * @returns {Promise<{ result: number }>} A promise that resolves with the horizontal field of view in degrees.\n * @since 0.0.1\n */\n getHorizontalFov(): Promise<{\n result: number;\n }>;\n\n /**\n * Gets the supported picture sizes for all cameras.\n *\n * @returns {Promise<{ supportedPictureSizes: SupportedPictureSizes[] }>} A promise that resolves with the list of supported sizes.\n * @since 7.4.0\n */\n getSupportedPictureSizes(): Promise<{\n supportedPictureSizes: SupportedPictureSizes[];\n }>;\n\n /**\n * Sets the flash mode for the active camera.\n *\n * @param {{ flashMode: CameraPreviewFlashMode | string }} options - The desired flash mode.\n * @returns {Promise<void>} A promise that resolves when the flash mode is set.\n * @since 0.0.1\n */\n setFlashMode(options: {\n flashMode: CameraPreviewFlashMode | string;\n }): Promise<void>;\n\n /**\n * Toggles between the front and rear cameras.\n *\n * @returns {Promise<void>} A promise that resolves when the camera is flipped.\n * @since 0.0.1\n */\n flip(): Promise<void>;\n\n /**\n * Sets the opacity of the camera preview.\n *\n * @param {CameraOpacityOptions} options - The opacity options.\n * @returns {Promise<void>} A promise that resolves when the opacity is set.\n * @since 0.0.1\n */\n setOpacity(options: CameraOpacityOptions): Promise<void>;\n\n /**\n * Stops an ongoing video recording.\n *\n * @returns {Promise<{ videoFilePath: string }>} A promise that resolves with the path to the recorded video file.\n * @since 0.0.1\n */\n stopRecordVideo(): Promise<{ videoFilePath: string }>;\n\n /**\n * Starts recording a video.\n *\n * @param {CameraPreviewOptions} options - The options for video recording. Only iOS.\n * @returns {Promise<void>} A promise that resolves when video recording starts.\n * @since 0.0.1\n */\n startRecordVideo(options: CameraPreviewOptions): Promise<void>;\n\n /**\n * Checks if the camera preview is currently running.\n *\n * @returns {Promise<{ isRunning: boolean }>} A promise that resolves with the running state.\n * @since 7.5.0\n * @platform android, ios\n */\n isRunning(): Promise<{ isRunning: boolean }>;\n\n /**\n * Gets all available camera devices.\n *\n * @returns {Promise<{ devices: CameraDevice[] }>} A promise that resolves with the list of available camera devices.\n * @since 7.5.0\n * @platform android, ios\n */\n getAvailableDevices(): Promise<{ devices: CameraDevice[] }>;\n\n /**\n * Gets the current zoom state, including min/max and current lens info.\n *\n * @returns {Promise<{ min: number; max: number; current: number; lens: LensInfo }>} A promise that resolves with the zoom state.\n * @since 7.5.0\n * @platform android, ios\n */\n getZoom(): Promise<{\n min: number;\n max: number;\n current: number;\n lens: LensInfo;\n }>;\n\n /**\n * Returns zoom button values for quick switching.\n * - iOS/Android: includes 0.5 if ultra-wide available; 1 and 2 if wide available; 3 if telephoto available\n * - Web: unsupported\n * @since 7.5.0\n * @platform android, ios\n */\n getZoomButtonValues(): Promise<{ values: number[] }>;\n\n /**\n * Sets the zoom level of the camera.\n *\n * @param {{ level: number; ramp?: boolean; autoFocus?: boolean }} options - The desired zoom level. `ramp` is currently unused. `autoFocus` defaults to true.\n * @returns {Promise<void>} A promise that resolves when the zoom level is set.\n * @since 7.5.0\n * @platform android, ios\n */\n setZoom(options: {\n level: number;\n ramp?: boolean;\n autoFocus?: boolean;\n }): Promise<void>;\n\n /**\n * Gets the current flash mode.\n *\n * @returns {Promise<{ flashMode: FlashMode }>} A promise that resolves with the current flash mode.\n * @since 7.5.0\n * @platform android, ios\n */\n getFlashMode(): Promise<{ flashMode: FlashMode }>;\n\n /**\n * Removes all registered listeners.\n *\n * @since 7.5.0\n * @platform android, ios\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Switches the active camera to the one with the specified `deviceId`.\n *\n * @param {{ deviceId: string }} options - The ID of the device to switch to.\n * @returns {Promise<void>} A promise that resolves when the camera is switched.\n * @since 7.5.0\n * @platform android, ios\n */\n setDeviceId(options: { deviceId: string }): Promise<void>;\n\n /**\n * Gets the ID of the currently active camera device.\n *\n * @returns {Promise<{ deviceId: string }>} A promise that resolves with the current device ID.\n * @since 7.5.0\n * @platform android, ios\n */\n getDeviceId(): Promise<{ deviceId: string }>;\n\n /**\n * Gets the current preview size and position.\n * @returns {Promise<{x: number, y: number, width: number, height: number}>}\n * @since 7.5.0\n * @platform android, ios\n */\n getPreviewSize(): Promise<{\n x: number;\n y: number;\n width: number;\n height: number;\n }>;\n /**\n * Sets the preview size and position.\n * @param options The new position and dimensions.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.5.0\n * @platform android, ios\n */\n setPreviewSize(options: {\n x?: number;\n y?: number;\n width: number;\n height: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Sets the camera focus to a specific point in the preview.\n *\n * Note: The plugin does not attach any native tap-to-focus gesture handlers. Handle taps in\n * your HTML/JS (e.g., on the overlaying UI), then pass normalized coordinates here.\n *\n * @param {Object} options - The focus options.\n * @param {number} options.x - The x coordinate in the preview view to focus on (0-1 normalized).\n * @param {number} options.y - The y coordinate in the preview view to focus on (0-1 normalized).\n * @returns {Promise<void>} A promise that resolves when the focus is set.\n * @since 7.5.0\n * @platform android, ios\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n\n /**\n * Adds a listener for screen resize events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"screenResize\",\n listenerFunc: (data: {\n width: number;\n height: number;\n x: number;\n y: number;\n }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for orientation change events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"orientationChange\",\n listenerFunc: (data: { orientation: DeviceOrientation }) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Deletes a file at the given absolute path on the device.\n * Use this to quickly clean up temporary images created with `storeToFile`.\n * On web, this is not supported and will throw.\n * @since 7.5.0\n * @platform android, ios\n */\n deleteFile(options: { path: string }): Promise<{ success: boolean }>;\n\n /**\n * Gets the safe area insets for devices.\n * Returns the orientation-aware notch/camera cutout inset and the current orientation.\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch moved to side).\n * This specifically targets the cutout area (notch, punch hole, etc.) that all modern phones have.\n *\n * Android: Values returned in dp (logical pixels).\n * iOS: Values returned in physical pixels, excluding status bar (only pure notch/cutout size).\n *\n * @platform android, ios\n */\n getSafeAreaInsets(): Promise<SafeAreaInsets>;\n\n /**\n * Gets the current device orientation in a cross-platform format.\n * @since 7.5.0\n * @platform android, ios\n */\n getOrientation(): Promise<{ orientation: DeviceOrientation }>;\n\n /**\n * Returns the exposure modes supported by the active camera.\n * Modes can include: 'locked', 'auto', 'continuous', 'custom'.\n * @platform android, ios\n */\n getExposureModes(): Promise<{ modes: ExposureMode[] }>;\n\n /**\n * Returns the current exposure mode.\n * @platform android, ios\n */\n getExposureMode(): Promise<{ mode: ExposureMode }>;\n\n /**\n * Sets the exposure mode.\n * @platform android, ios\n */\n setExposureMode(options: { mode: ExposureMode }): Promise<void>;\n\n /**\n * Returns the exposure compensation (EV bias) supported range.\n * @platform ios\n */\n getExposureCompensationRange(): Promise<{\n min: number;\n max: number;\n step: number;\n }>;\n\n /**\n * Returns the current exposure compensation (EV bias).\n * @platform ios\n */\n getExposureCompensation(): Promise<{ value: number }>;\n\n /**\n * Sets the exposure compensation (EV bias). Value will be clamped to range.\n * @platform ios\n */\n setExposureCompensation(options: { value: number }): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAUA,MAAM,CAAN,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,sCAAwB,CAAA;IACxB,sCAAwB,CAAA;IACxB,qCAAuB,CAAA;IACvB,sCAAwB,CAAA;IACxB,2BAAa,CAAA;IACb,oCAAsB,CAAA;IACtB,+BAAiB,CAAA;AACnB,CAAC,EARW,UAAU,KAAV,UAAU,QAQrB","sourcesContent":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport type CameraPosition = \"rear\" | \"front\";\n\nexport type FlashMode = CameraPreviewFlashMode;\n\nexport type GridMode = \"none\" | \"3x3\" | \"4x4\";\n\nexport type CameraPositioning = \"center\" | \"top\" | \"bottom\";\n\nexport enum DeviceType {\n ULTRA_WIDE = \"ultraWide\",\n WIDE_ANGLE = \"wideAngle\",\n TELEPHOTO = \"telephoto\",\n TRUE_DEPTH = \"trueDepth\",\n DUAL = \"dual\",\n DUAL_WIDE = \"dualWide\",\n TRIPLE = \"triple\",\n}\n\n/**\n * Represents a single camera lens on a device. A {@link CameraDevice} can have multiple lenses.\n */\nexport interface CameraLens {\n /** A human-readable name for the lens, e.g., \"Ultra-Wide\". */\n label: string;\n /** The type of the camera lens. */\n deviceType: DeviceType;\n /** The focal length of the lens in millimeters. */\n focalLength: number;\n /** The base zoom factor for this lens (e.g., 0.5 for ultra-wide, 1.0 for wide). */\n baseZoomRatio: number;\n /** The minimum zoom factor supported by this specific lens. */\n minZoom: number;\n /** The maximum zoom factor supported by this specific lens. */\n maxZoom: number;\n}\n\n/**\n * Represents a physical camera on the device (e.g., the front-facing camera).\n */\nexport interface CameraDevice {\n /** A unique identifier for the camera device. */\n deviceId: string;\n /** A human-readable name for the camera device. */\n label: string;\n /** The physical position of the camera on the device. */\n position: CameraPosition;\n /** A list of all available lenses for this camera device. */\n lenses: CameraLens[];\n /** The overall minimum zoom factor available across all lenses on this device. */\n minZoom: number;\n /** The overall maximum zoom factor available across all lenses on this device. */\n maxZoom: number;\n /** Identifies whether the device is a logical camera (composed of multiple physical lenses). */\n isLogical: boolean;\n}\n\n/**\n * Represents the detailed information of the currently active lens.\n */\nexport interface LensInfo {\n /** The focal length of the active lens in millimeters. */\n focalLength: number;\n /** The device type of the active lens. */\n deviceType: DeviceType;\n /** The base zoom ratio of the active lens (e.g., 0.5x, 1.0x). */\n baseZoomRatio: number;\n /** The current digital zoom factor applied on top of the base zoom. */\n digitalZoom: number;\n}\n\n/**\n * Defines the configuration options for starting the camera preview.\n */\nexport interface CameraPreviewOptions {\n /**\n * The parent element to attach the video preview to.\n * @platform web\n */\n parent?: string;\n /**\n * A CSS class name to add to the preview element.\n * @platform web\n */\n className?: string;\n /**\n * The width of the preview in pixels. Defaults to the screen width.\n * @platform android, ios, web\n */\n width?: number;\n /**\n * The height of the preview in pixels. Defaults to the screen height.\n * @platform android, ios, web\n */\n height?: number;\n /**\n * The horizontal origin of the preview, in pixels.\n * @platform android, ios\n */\n x?: number;\n /**\n * The vertical origin of the preview, in pixels.\n * @platform android, ios\n */\n y?: number;\n /**\n * The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'.\n * Cannot be set if width or height is provided, otherwise the call will be rejected.\n * Use setPreviewSize to adjust size after starting.\n *\n * @since 2.0.0\n */\n aspectRatio?: \"4:3\" | \"16:9\";\n /**\n * The grid overlay to display on the camera preview.\n * @default \"none\"\n * @since 2.1.0\n */\n gridMode?: GridMode;\n /**\n * Adjusts the y-position to account for safe areas (e.g., notches).\n * @platform ios\n * @default false\n */\n includeSafeAreaInsets?: boolean;\n /**\n * If true, places the preview behind the webview.\n * @platform android\n * @default true\n */\n toBack?: boolean;\n /**\n * Bottom padding for the preview, in pixels.\n * @platform android, ios\n */\n paddingBottom?: number;\n /**\n * Whether to rotate the preview when the device orientation changes.\n * @platform ios\n * @default true\n */\n rotateWhenOrientationChanged?: boolean;\n /**\n * The camera to use.\n * @default \"rear\"\n */\n position?: CameraPosition | string;\n /**\n * If true, saves the captured image to a file and returns the file path.\n * If false, returns a base64 encoded string.\n * @default false\n */\n storeToFile?: boolean;\n /**\n * If true, prevents the plugin from rotating the image based on EXIF data.\n * @platform android\n * @default false\n */\n disableExifHeaderStripping?: boolean;\n /**\n * If true, disables the audio stream, preventing audio permission requests.\n * @default true\n */\n disableAudio?: boolean;\n /**\n * If true, locks the device orientation while the camera is active.\n * @platform android\n * @default false\n */\n lockAndroidOrientation?: boolean;\n /**\n * If true, allows the camera preview's opacity to be changed.\n * @platform android, web\n * @default false\n */\n enableOpacity?: boolean;\n\n /**\n * If true, disables the visual focus indicator when tapping to focus.\n * @platform android, ios\n * @default false\n */\n disableFocusIndicator?: boolean;\n /**\n * The `deviceId` of the camera to use. If provided, `position` is ignored.\n * @platform ios\n */\n deviceId?: string;\n /**\n * The initial zoom level when starting the camera preview.\n * If the requested zoom level is not available, the native plugin will reject.\n * @default 1.0\n * @platform android, ios\n * @since 2.2.0\n */\n initialZoomLevel?: number;\n /**\n * The vertical positioning of the camera preview.\n * @default \"center\"\n * @platform android, ios, web\n * @since 2.3.0\n */\n positioning?: CameraPositioning;\n /**\n * If true, enables video capture capabilities when the camera starts.\n * @default false\n * @platform android\n * @since 7.11.0\n */\n enableVideoMode?: boolean;\n}\n\n/**\n * Defines the options for capturing a picture.\n */\nexport interface CameraPreviewPictureOptions {\n /**\n * The maximum height of the picture in pixels. The image will be resized to fit within this height while maintaining aspect ratio.\n * If not specified the captured image will match the preview's visible area.\n */\n height?: number;\n /**\n * The maximum width of the picture in pixels. The image will be resized to fit within this width while maintaining aspect ratio.\n * If not specified the captured image will match the preview's visible area.\n */\n width?: number;\n /**\n * The quality of the captured image, from 0 to 100.\n * Does not apply to `png` format.\n * @default 85\n */\n quality?: number;\n /**\n * The format of the captured image.\n * @default \"jpeg\"\n */\n format?: PictureFormat;\n /**\n * If true, the captured image will be saved to the user's gallery.\n * @default false\n * @since 7.5.0\n */\n saveToGallery?: boolean;\n /**\n * If true, the plugin will attempt to add GPS location data to the image's EXIF metadata.\n * This may prompt the user for location permissions.\n * @default false\n * @since 7.6.0\n */\n withExifLocation?: boolean;\n /**\n * If true, the plugin will embed a timestamp in the top-right corner of the image.\n * @default false\n * @since 7.17.0\n */\n embedTimestamp?: boolean;\n /**\n * If true, the plugin will embed the current location in the top-right corner of the image.\n * Requires `withExifLocation` to be enabled.\n * @default false\n * @since 7.18.0\n */\n embedLocation?: boolean;\n}\n\n/** Represents EXIF data extracted from an image. */\nexport interface ExifData {\n [key: string]: any;\n}\n\nexport type PictureFormat = \"jpeg\" | \"png\";\n\n/** Defines a standard picture size with width and height. */\nexport interface PictureSize {\n /** The width of the picture in pixels. */\n width: number;\n /** The height of the picture in pixels. */\n height: number;\n}\n\n/** Represents the supported picture sizes for a camera facing a certain direction. */\nexport interface SupportedPictureSizes {\n /** The camera direction (\"front\" or \"rear\"). */\n facing: string;\n /** A list of supported picture sizes for this camera. */\n supportedPictureSizes: PictureSize[];\n}\n\n/**\n * Defines the options for capturing a sample frame from the camera preview.\n */\nexport interface CameraSampleOptions {\n /**\n * The quality of the captured sample, from 0 to 100.\n * @default 85\n */\n quality?: number;\n}\n\n/**\n * The available flash modes for the camera.\n * 'torch' is a continuous light mode.\n */\nexport type CameraPreviewFlashMode = \"off\" | \"on\" | \"auto\" | \"torch\";\n\n/** Reusable exposure mode type for cross-platform support. */\nexport type ExposureMode = \"AUTO\" | \"LOCK\" | \"CONTINUOUS\" | \"CUSTOM\";\n\n/**\n * Defines the options for setting the camera preview's opacity.\n */\nexport interface CameraOpacityOptions {\n /**\n * The opacity percentage, from 0.0 (fully transparent) to 1.0 (fully opaque).\n * @default 1.0\n */\n opacity?: number;\n}\n\n/**\n * Represents safe area insets for devices.\n * Android: Values are expressed in logical pixels (dp) to match JS layout units.\n * iOS: Values are expressed in physical pixels and exclude status bar.\n */\nexport interface SafeAreaInsets {\n /** Current device orientation (1 = portrait, 2 = landscape, 0 = unknown). */\n orientation: number;\n /**\n * Orientation-aware notch/camera cutout inset (excluding status bar).\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch at side).\n * Android: Value in dp, iOS: Value in pixels (status bar excluded).\n */\n top: number;\n}\n\n/**\n * Canonical device orientation values across platforms.\n */\nexport type DeviceOrientation =\n | \"portrait\"\n | \"landscape-left\"\n | \"landscape-right\"\n | \"portrait-upside-down\"\n | \"unknown\";\n\n/**\n * The main interface for the CameraPreview plugin.\n */\nexport interface CameraPreviewPlugin {\n /**\n * Starts the camera preview.\n *\n * @param {CameraPreviewOptions} options - The configuration for the camera preview.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the preview dimensions.\n * @since 0.0.1\n */\n start(options: CameraPreviewOptions): Promise<{\n /** The width of the preview in pixels. */\n width: number;\n /** The height of the preview in pixels. */\n height: number;\n /** The horizontal origin of the preview, in pixels. */\n x: number;\n /** The vertical origin of the preview, in pixels. */\n y: number;\n }>;\n\n /**\n * Stops the camera preview.\n *\n * @returns {Promise<void>} A promise that resolves when the camera preview is stopped.\n * @since 0.0.1\n */\n stop(): Promise<void>;\n\n /**\n * Captures a picture from the camera.\n *\n * If `storeToFile` was set to `true` when starting the preview, the returned\n * `value` will be an absolute file path on the device instead of a base64 string. Use getBase64FromFilePath to get the base64 string from the file path.\n *\n * @param {CameraPreviewPictureOptions} options - The options for capturing the picture.\n * @returns {Promise<{ value: string; exif: ExifData }>} Resolves with:\n * - `value`: base64 string, or file path if `storeToFile` is true\n * - `exif`: extracted EXIF metadata when available\n * @since 0.0.1\n */\n capture(\n options: CameraPreviewPictureOptions,\n ): Promise<{ value: string; exif: ExifData }>;\n\n /**\n * Captures a single frame from the camera preview stream.\n *\n * @param {CameraSampleOptions} options - The options for capturing the sample.\n * @returns {Promise<{ value: string }>} A promise that resolves with the sample image as a base64 encoded string.\n * @since 0.0.1\n */\n captureSample(options: CameraSampleOptions): Promise<{ value: string }>;\n\n /**\n * Gets the flash modes supported by the active camera.\n *\n * @returns {Promise<{ result: CameraPreviewFlashMode[] }>} A promise that resolves with an array of supported flash modes.\n * @since 0.0.1\n */\n getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }>;\n\n /**\n * Set the aspect ratio of the camera preview.\n *\n * @param {{ aspectRatio: '4:3' | '16:9'; x?: number; y?: number }} options - The desired aspect ratio and optional position.\n * - aspectRatio: The desired aspect ratio ('4:3' or '16:9')\n * - x: Optional x coordinate for positioning. If not provided, view will be auto-centered horizontally.\n * - y: Optional y coordinate for positioning. If not provided, view will be auto-centered vertically.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.5.0\n * @platform android, ios\n */\n setAspectRatio(options: {\n aspectRatio: \"4:3\" | \"16:9\";\n x?: number;\n y?: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Gets the current aspect ratio of the camera preview.\n *\n * @returns {Promise<{ aspectRatio: '4:3' | '16:9' }>} A promise that resolves with the current aspect ratio.\n * @since 7.5.0\n * @platform android, ios\n */\n getAspectRatio(): Promise<{ aspectRatio: \"4:3\" | \"16:9\" }>;\n\n /**\n * Sets the grid mode of the camera preview overlay.\n *\n * @param {{ gridMode: GridMode }} options - The desired grid mode ('none', '3x3', or '4x4').\n * @returns {Promise<void>} A promise that resolves when the grid mode is set.\n * @since 8.0.0\n */\n setGridMode(options: { gridMode: GridMode }): Promise<void>;\n\n /**\n * Gets the current grid mode of the camera preview overlay.\n *\n * @returns {Promise<{ gridMode: GridMode }>} A promise that resolves with the current grid mode.\n * @since 8.0.0\n */\n getGridMode(): Promise<{ gridMode: GridMode }>;\n\n /**\n * Gets the horizontal field of view (FoV) for the active camera.\n * Note: This can be an estimate on some devices.\n *\n * @returns {Promise<{ result: number }>} A promise that resolves with the horizontal field of view in degrees.\n * @since 0.0.1\n */\n getHorizontalFov(): Promise<{\n result: number;\n }>;\n\n /**\n * Gets the supported picture sizes for all cameras.\n *\n * @returns {Promise<{ supportedPictureSizes: SupportedPictureSizes[] }>} A promise that resolves with the list of supported sizes.\n * @since 7.4.0\n */\n getSupportedPictureSizes(): Promise<{\n supportedPictureSizes: SupportedPictureSizes[];\n }>;\n\n /**\n * Sets the flash mode for the active camera.\n *\n * @param {{ flashMode: CameraPreviewFlashMode | string }} options - The desired flash mode.\n * @returns {Promise<void>} A promise that resolves when the flash mode is set.\n * @since 0.0.1\n */\n setFlashMode(options: {\n flashMode: CameraPreviewFlashMode | string;\n }): Promise<void>;\n\n /**\n * Toggles between the front and rear cameras.\n *\n * @returns {Promise<void>} A promise that resolves when the camera is flipped.\n * @since 0.0.1\n */\n flip(): Promise<void>;\n\n /**\n * Sets the opacity of the camera preview.\n *\n * @param {CameraOpacityOptions} options - The opacity options.\n * @returns {Promise<void>} A promise that resolves when the opacity is set.\n * @since 0.0.1\n */\n setOpacity(options: CameraOpacityOptions): Promise<void>;\n\n /**\n * Stops an ongoing video recording.\n *\n * @returns {Promise<{ videoFilePath: string }>} A promise that resolves with the path to the recorded video file.\n * @since 0.0.1\n */\n stopRecordVideo(): Promise<{ videoFilePath: string }>;\n\n /**\n * Starts recording a video.\n *\n * @param {CameraPreviewOptions} options - The options for video recording. Only iOS.\n * @returns {Promise<void>} A promise that resolves when video recording starts.\n * @since 0.0.1\n */\n startRecordVideo(options: CameraPreviewOptions): Promise<void>;\n\n /**\n * Checks if the camera preview is currently running.\n *\n * @returns {Promise<{ isRunning: boolean }>} A promise that resolves with the running state.\n * @since 7.5.0\n * @platform android, ios\n */\n isRunning(): Promise<{ isRunning: boolean }>;\n\n /**\n * Gets all available camera devices.\n *\n * @returns {Promise<{ devices: CameraDevice[] }>} A promise that resolves with the list of available camera devices.\n * @since 7.5.0\n * @platform android, ios\n */\n getAvailableDevices(): Promise<{ devices: CameraDevice[] }>;\n\n /**\n * Gets the current zoom state, including min/max and current lens info.\n *\n * @returns {Promise<{ min: number; max: number; current: number; lens: LensInfo }>} A promise that resolves with the zoom state.\n * @since 7.5.0\n * @platform android, ios\n */\n getZoom(): Promise<{\n min: number;\n max: number;\n current: number;\n lens: LensInfo;\n }>;\n\n /**\n * Returns zoom button values for quick switching.\n * - iOS/Android: includes 0.5 if ultra-wide available; 1 and 2 if wide available; 3 if telephoto available\n * - Web: unsupported\n * @since 7.5.0\n * @platform android, ios\n */\n getZoomButtonValues(): Promise<{ values: number[] }>;\n\n /**\n * Sets the zoom level of the camera.\n *\n * @param {{ level: number; ramp?: boolean; autoFocus?: boolean }} options - The desired zoom level. `ramp` is currently unused. `autoFocus` defaults to true.\n * @returns {Promise<void>} A promise that resolves when the zoom level is set.\n * @since 7.5.0\n * @platform android, ios\n */\n setZoom(options: {\n level: number;\n ramp?: boolean;\n autoFocus?: boolean;\n }): Promise<void>;\n\n /**\n * Gets the current flash mode.\n *\n * @returns {Promise<{ flashMode: FlashMode }>} A promise that resolves with the current flash mode.\n * @since 7.5.0\n * @platform android, ios\n */\n getFlashMode(): Promise<{ flashMode: FlashMode }>;\n\n /**\n * Removes all registered listeners.\n *\n * @since 7.5.0\n * @platform android, ios\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Switches the active camera to the one with the specified `deviceId`.\n *\n * @param {{ deviceId: string }} options - The ID of the device to switch to.\n * @returns {Promise<void>} A promise that resolves when the camera is switched.\n * @since 7.5.0\n * @platform android, ios\n */\n setDeviceId(options: { deviceId: string }): Promise<void>;\n\n /**\n * Gets the ID of the currently active camera device.\n *\n * @returns {Promise<{ deviceId: string }>} A promise that resolves with the current device ID.\n * @since 7.5.0\n * @platform android, ios\n */\n getDeviceId(): Promise<{ deviceId: string }>;\n\n /**\n * Gets the current preview size and position.\n * @returns {Promise<{x: number, y: number, width: number, height: number}>}\n * @since 7.5.0\n * @platform android, ios\n */\n getPreviewSize(): Promise<{\n x: number;\n y: number;\n width: number;\n height: number;\n }>;\n /**\n * Sets the preview size and position.\n * @param options The new position and dimensions.\n * @returns {Promise<{ width: number; height: number; x: number; y: number }>} A promise that resolves with the actual preview dimensions and position.\n * @since 7.5.0\n * @platform android, ios\n */\n setPreviewSize(options: {\n x?: number;\n y?: number;\n width: number;\n height: number;\n }): Promise<{\n width: number;\n height: number;\n x: number;\n y: number;\n }>;\n\n /**\n * Sets the camera focus to a specific point in the preview.\n *\n * Note: The plugin does not attach any native tap-to-focus gesture handlers. Handle taps in\n * your HTML/JS (e.g., on the overlaying UI), then pass normalized coordinates here.\n *\n * @param {Object} options - The focus options.\n * @param {number} options.x - The x coordinate in the preview view to focus on (0-1 normalized).\n * @param {number} options.y - The y coordinate in the preview view to focus on (0-1 normalized).\n * @returns {Promise<void>} A promise that resolves when the focus is set.\n * @since 7.5.0\n * @platform android, ios\n */\n setFocus(options: { x: number; y: number }): Promise<void>;\n\n /**\n * Adds a listener for screen resize events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"screenResize\",\n listenerFunc: (data: {\n width: number;\n height: number;\n x: number;\n y: number;\n }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Adds a listener for orientation change events.\n * @param {string} eventName - The event name to listen for.\n * @param {Function} listenerFunc - The function to call when the event is triggered.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves with a handle to the listener.\n * @since 7.5.0\n * @platform android, ios\n */\n addListener(\n eventName: \"orientationChange\",\n listenerFunc: (data: { orientation: DeviceOrientation }) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Deletes a file at the given absolute path on the device.\n * Use this to quickly clean up temporary images created with `storeToFile`.\n * On web, this is not supported and will throw.\n * @since 7.5.0\n * @platform android, ios\n */\n deleteFile(options: { path: string }): Promise<{ success: boolean }>;\n\n /**\n * Gets the safe area insets for devices.\n * Returns the orientation-aware notch/camera cutout inset and the current orientation.\n * In portrait mode: returns top inset (notch at top).\n * In landscape mode: returns left inset (notch moved to side).\n * This specifically targets the cutout area (notch, punch hole, etc.) that all modern phones have.\n *\n * Android: Values returned in dp (logical pixels).\n * iOS: Values returned in physical pixels, excluding status bar (only pure notch/cutout size).\n *\n * @platform android, ios\n */\n getSafeAreaInsets(): Promise<SafeAreaInsets>;\n\n /**\n * Gets the current device orientation in a cross-platform format.\n * @since 7.5.0\n * @platform android, ios\n */\n getOrientation(): Promise<{ orientation: DeviceOrientation }>;\n\n /**\n * Returns the exposure modes supported by the active camera.\n * Modes can include: 'locked', 'auto', 'continuous', 'custom'.\n * @platform android, ios\n */\n getExposureModes(): Promise<{ modes: ExposureMode[] }>;\n\n /**\n * Returns the current exposure mode.\n * @platform android, ios\n */\n getExposureMode(): Promise<{ mode: ExposureMode }>;\n\n /**\n * Sets the exposure mode.\n * @platform android, ios\n */\n setExposureMode(options: { mode: ExposureMode }): Promise<void>;\n\n /**\n * Returns the exposure compensation (EV bias) supported range.\n * @platform ios\n */\n getExposureCompensationRange(): Promise<{\n min: number;\n max: number;\n step: number;\n }>;\n\n /**\n * Returns the current exposure compensation (EV bias).\n * @platform ios\n */\n getExposureCompensation(): Promise<{ value: number }>;\n\n /**\n * Sets the exposure compensation (EV bias). Value will be clamped to range.\n * @platform ios\n */\n setExposureCompensation(options: { value: number }): Promise<void>;\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import AVFoundation
|
|
2
2
|
import UIKit
|
|
3
3
|
import CoreLocation
|
|
4
|
+
import UniformTypeIdentifiers
|
|
4
5
|
|
|
5
6
|
class CameraController: NSObject {
|
|
6
7
|
private func getVideoOrientation() -> AVCaptureVideoOrientation {
|
|
@@ -888,7 +889,7 @@ extension CameraController {
|
|
|
888
889
|
self.updateVideoOrientation()
|
|
889
890
|
}
|
|
890
891
|
|
|
891
|
-
func captureImage(width: Int?, height: Int?, quality: Float, gpsLocation: CLLocation?, completion: @escaping (UIImage?, Data?, [AnyHashable: Any]?, Error?) -> Void) {
|
|
892
|
+
func captureImage(width: Int?, height: Int?, quality: Float, gpsLocation: CLLocation?, embedTimestamp: Bool, embedLocation: Bool, completion: @escaping (UIImage?, Data?, [AnyHashable: Any]?, Error?) -> Void) {
|
|
892
893
|
guard let photoOutput = self.photoOutput else {
|
|
893
894
|
completion(nil, nil, nil, NSError(domain: "Camera", code: 0, userInfo: [NSLocalizedDescriptionKey: "Photo output is not available"]))
|
|
894
895
|
return
|
|
@@ -972,7 +973,25 @@ extension CameraController {
|
|
|
972
973
|
print("[CameraPreview] Applied aspect ratio cropping for \(aspectRatio): \(finalImage.size.width)x\(finalImage.size.height)")
|
|
973
974
|
}
|
|
974
975
|
|
|
976
|
+
// Draw overlays if either flag is set (timestamp and/or location)
|
|
977
|
+
if embedTimestamp || embedLocation {
|
|
978
|
+
let when: String? = embedTimestamp
|
|
979
|
+
? self.makeTimestampString(from: photoData, metadata: metadata)
|
|
980
|
+
: nil
|
|
981
|
+
|
|
982
|
+
let whereStr: String? = embedLocation
|
|
983
|
+
? self.makeLocationString(from: gpsLocation, photoData: photoData, metadata: metadata)
|
|
984
|
+
: nil
|
|
985
|
+
|
|
986
|
+
if (when?.isEmpty ?? true) && (whereStr?.isEmpty ?? true) {
|
|
987
|
+
// Nothing to draw (e.g., embedLocation=true but no GPS present) → skip
|
|
988
|
+
} else {
|
|
989
|
+
finalImage = self.drawTimestampAndLocation(on: finalImage, when: when, where: whereStr)
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
|
|
975
993
|
completion(finalImage, photoData, metadata, nil)
|
|
994
|
+
|
|
976
995
|
// End capture lifecycle
|
|
977
996
|
self.isCapturingPhoto = false
|
|
978
997
|
if self.stopRequestedAfterCapture {
|
|
@@ -983,6 +1002,206 @@ extension CameraController {
|
|
|
983
1002
|
photoOutput.capturePhoto(with: settings, delegate: self)
|
|
984
1003
|
}
|
|
985
1004
|
|
|
1005
|
+
/// Draws timestamp and/or location pills at the top-right. Pass nil to skip either line.
|
|
1006
|
+
func drawTimestampAndLocation(on image: UIImage, when: String?, where whereStr: String?) -> UIImage {
|
|
1007
|
+
let base = image.fixedOrientation() ?? image
|
|
1008
|
+
let scale = base.scale
|
|
1009
|
+
let size = base.size
|
|
1010
|
+
|
|
1011
|
+
// Style (match drawTimestamp)
|
|
1012
|
+
let textColor: UIColor = .white
|
|
1013
|
+
let backgroundColor = UIColor(white: 0.12, alpha: 0.22)
|
|
1014
|
+
let paddingH: CGFloat = 16
|
|
1015
|
+
let paddingV: CGFloat = 10
|
|
1016
|
+
let cornerRadius: CGFloat = 10
|
|
1017
|
+
let margin: CGFloat = 12
|
|
1018
|
+
let gap: CGFloat = 8
|
|
1019
|
+
|
|
1020
|
+
// ≈3.5% of image width (≥10pt)
|
|
1021
|
+
let fontPointSize = max(10, size.width * 0.035)
|
|
1022
|
+
let font: UIFont = .systemFont(ofSize: fontPointSize, weight: .semibold)
|
|
1023
|
+
|
|
1024
|
+
let format = UIGraphicsImageRendererFormat.default()
|
|
1025
|
+
format.scale = scale
|
|
1026
|
+
format.opaque = true
|
|
1027
|
+
|
|
1028
|
+
return UIGraphicsImageRenderer(size: size, format: format).image { ctx in
|
|
1029
|
+
base.draw(in: CGRect(origin: .zero, size: size))
|
|
1030
|
+
|
|
1031
|
+
func drawPill(_ text: String, top: CGFloat) -> CGFloat {
|
|
1032
|
+
let attrs: [NSAttributedString.Key: Any] = [.font: font, .foregroundColor: textColor]
|
|
1033
|
+
let textSize = (text as NSString).size(withAttributes: attrs)
|
|
1034
|
+
let bgSize = CGSize(width: textSize.width + paddingH * 2,
|
|
1035
|
+
height: textSize.height + paddingV * 2)
|
|
1036
|
+
let origin = CGPoint(x: size.width - bgSize.width - margin, y: top)
|
|
1037
|
+
let rect = CGRect(origin: origin, size: bgSize)
|
|
1038
|
+
|
|
1039
|
+
// shadowed rounded bg
|
|
1040
|
+
let path = UIBezierPath(roundedRect: rect, cornerRadius: cornerRadius)
|
|
1041
|
+
ctx.cgContext.saveGState()
|
|
1042
|
+
ctx.cgContext.setShadow(offset: CGSize(width: 0, height: 2),
|
|
1043
|
+
blur: 6,
|
|
1044
|
+
color: UIColor.black.withAlphaComponent(0.25).cgColor)
|
|
1045
|
+
backgroundColor.setFill()
|
|
1046
|
+
path.fill()
|
|
1047
|
+
ctx.cgContext.restoreGState()
|
|
1048
|
+
|
|
1049
|
+
// high-quality text
|
|
1050
|
+
let g = ctx.cgContext
|
|
1051
|
+
g.setAllowsAntialiasing(true)
|
|
1052
|
+
g.setShouldAntialias(true)
|
|
1053
|
+
g.setAllowsFontSmoothing(true)
|
|
1054
|
+
g.setShouldSmoothFonts(true)
|
|
1055
|
+
g.setShouldSubpixelPositionFonts(true)
|
|
1056
|
+
g.interpolationQuality = .high
|
|
1057
|
+
|
|
1058
|
+
(text as NSString).draw(at: CGPoint(x: rect.minX + paddingH, y: rect.minY + paddingV),
|
|
1059
|
+
withAttributes: attrs)
|
|
1060
|
+
|
|
1061
|
+
return rect.maxY
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
var top = margin
|
|
1065
|
+
if let w = when, !w.isEmpty {
|
|
1066
|
+
top = drawPill(w, top: top) + gap
|
|
1067
|
+
}
|
|
1068
|
+
if let loc = whereStr, !loc.isEmpty {
|
|
1069
|
+
_ = drawPill(loc, top: (top == margin ? margin : top))
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
func makeTimestampString(from photoData: Data?, metadata: [AnyHashable: Any]?) -> String {
|
|
1075
|
+
func extractDateString(from meta: [String: Any]) -> String? {
|
|
1076
|
+
if let exif = meta[kCGImagePropertyExifDictionary as String] as? [String: Any] {
|
|
1077
|
+
if let s = exif[kCGImagePropertyExifDateTimeOriginal as String] as? String { return s }
|
|
1078
|
+
if let s = exif[kCGImagePropertyExifDateTimeDigitized as String] as? String { return s }
|
|
1079
|
+
}
|
|
1080
|
+
if let tiff = meta[kCGImagePropertyTIFFDictionary as String] as? [String: Any] {
|
|
1081
|
+
if let s = tiff[kCGImagePropertyTIFFDateTime as String] as? String { return s }
|
|
1082
|
+
}
|
|
1083
|
+
return nil
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
var raw: String?
|
|
1087
|
+
if let metadata = metadata as? [String: Any] {
|
|
1088
|
+
raw = extractDateString(from: metadata)
|
|
1089
|
+
}
|
|
1090
|
+
if raw == nil, let data = photoData,
|
|
1091
|
+
let src = CGImageSourceCreateWithData(data as CFData, nil),
|
|
1092
|
+
let props = CGImageSourceCopyPropertiesAtIndex(src, 0, nil) as? [String: Any] {
|
|
1093
|
+
raw = extractDateString(from: props)
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
let outFmt = DateFormatter()
|
|
1097
|
+
outFmt.locale = .current
|
|
1098
|
+
outFmt.timeZone = .current
|
|
1099
|
+
outFmt.dateFormat = "yyyy-MM-dd HH:mm:ss"
|
|
1100
|
+
|
|
1101
|
+
if let raw = raw {
|
|
1102
|
+
let df = DateFormatter()
|
|
1103
|
+
df.locale = Locale(identifier: "en_US_POSIX")
|
|
1104
|
+
df.timeZone = .current
|
|
1105
|
+
df.dateFormat = raw.contains(".") ? "yyyy:MM:dd HH:mm:ss.SSS" : "yyyy:MM:dd HH:mm:ss"
|
|
1106
|
+
if let d = df.date(from: raw) {
|
|
1107
|
+
return outFmt.string(from: d)
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
return outFmt.string(from: Date())
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
func makeLocationString(from location: CLLocation?,
|
|
1115
|
+
photoData: Data?,
|
|
1116
|
+
metadata: [AnyHashable: Any]?) -> String? {
|
|
1117
|
+
// 1) Prefer the explicit CLLocation that was just provided
|
|
1118
|
+
if let loc = location {
|
|
1119
|
+
let lat = String(format: "%.5f", loc.coordinate.latitude)
|
|
1120
|
+
let lon = String(format: "%.5f", loc.coordinate.longitude)
|
|
1121
|
+
return "\(lat), \(lon)"
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// 2) Fall back to EXIF GPS in metadata / photo data
|
|
1125
|
+
func extractGPS(_ meta: [String: Any]) -> (Double, Double)? {
|
|
1126
|
+
guard let gps = meta[kCGImagePropertyGPSDictionary as String] as? [String: Any] else { return nil }
|
|
1127
|
+
if let lat = gps[kCGImagePropertyGPSLatitude as String] as? Double,
|
|
1128
|
+
let latRef = gps[kCGImagePropertyGPSLatitudeRef as String] as? String,
|
|
1129
|
+
let lon = gps[kCGImagePropertyGPSLongitude as String] as? Double,
|
|
1130
|
+
let lonRef = gps[kCGImagePropertyGPSLongitudeRef as String] as? String {
|
|
1131
|
+
let signedLat = (latRef.uppercased() == "S") ? -lat : lat
|
|
1132
|
+
let signedLon = (lonRef.uppercased() == "W") ? -lon : lon
|
|
1133
|
+
return (signedLat, signedLon)
|
|
1134
|
+
}
|
|
1135
|
+
return nil
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
if let md = metadata as? [String: Any], let (lat, lon) = extractGPS(md) {
|
|
1139
|
+
return String(format: "%.5f, %.5f", lat, lon)
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
if let data = photoData,
|
|
1143
|
+
let src = CGImageSourceCreateWithData(data as CFData, nil),
|
|
1144
|
+
let props = CGImageSourceCopyPropertiesAtIndex(src, 0, nil) as? [String: Any],
|
|
1145
|
+
let (lat, lon) = extractGPS(props) {
|
|
1146
|
+
return String(format: "%.5f, %.5f", lat, lon)
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
return nil
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
// Create JPEG data from `image`, merging the original EXIF/GPS/etc. and forcing Orientation=1.
|
|
1153
|
+
func jpegDataPreservingMetadata(from image: UIImage,
|
|
1154
|
+
originalPhotoData: Data?,
|
|
1155
|
+
originalMetadata: [AnyHashable: Any]?,
|
|
1156
|
+
quality: CGFloat = 0.9) -> Data? {
|
|
1157
|
+
// Encode pixels first
|
|
1158
|
+
guard let cgImg = image.cgImage else { return image.jpegData(compressionQuality: quality) }
|
|
1159
|
+
let uiImageData = UIImage(cgImage: cgImg, scale: image.scale, orientation: .up)
|
|
1160
|
+
.jpegData(compressionQuality: quality)
|
|
1161
|
+
|
|
1162
|
+
// If we don’t have source metadata, just return the new JPEG
|
|
1163
|
+
guard let srcData = originalPhotoData, let newJPEG = uiImageData else { return uiImageData }
|
|
1164
|
+
|
|
1165
|
+
// Load base metadata from source, then overlay any explicit metadata dict we were given
|
|
1166
|
+
let cgSrc = CGImageSourceCreateWithData(srcData as CFData, nil)
|
|
1167
|
+
let baseMetadata: [String: Any]
|
|
1168
|
+
if let src = cgSrc,
|
|
1169
|
+
let props = CGImageSourceCopyPropertiesAtIndex(src, 0, nil) as? [String: Any] {
|
|
1170
|
+
var merged = props
|
|
1171
|
+
if let explicit = originalMetadata as? [String: Any] {
|
|
1172
|
+
for (k, v) in explicit { merged[k] = v }
|
|
1173
|
+
}
|
|
1174
|
+
baseMetadata = merged
|
|
1175
|
+
} else if let explicit = originalMetadata as? [String: Any] {
|
|
1176
|
+
baseMetadata = explicit
|
|
1177
|
+
} else {
|
|
1178
|
+
return newJPEG
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
// Prepare destination
|
|
1182
|
+
let dstData = NSMutableData()
|
|
1183
|
+
guard let cgDst = CGImageDestinationCreateWithData(dstData, UTType.jpeg.identifier as CFString, 1, nil) else {
|
|
1184
|
+
return newJPEG
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
// Force normalized orientation (pixels are already .up)
|
|
1188
|
+
var metaOut = baseMetadata
|
|
1189
|
+
if var tiff = metaOut[kCGImagePropertyTIFFDictionary as String] as? [String: Any] {
|
|
1190
|
+
tiff[kCGImagePropertyTIFFOrientation as String] = 1
|
|
1191
|
+
metaOut[kCGImagePropertyTIFFDictionary as String] = tiff
|
|
1192
|
+
}
|
|
1193
|
+
metaOut[kCGImagePropertyOrientation as String] = 1
|
|
1194
|
+
|
|
1195
|
+
// Write the new pixels + merged metadata
|
|
1196
|
+
if let cgImage = UIImage(data: newJPEG)?.cgImage {
|
|
1197
|
+
CGImageDestinationAddImage(cgDst, cgImage, metaOut as CFDictionary)
|
|
1198
|
+
CGImageDestinationFinalize(cgDst)
|
|
1199
|
+
return (dstData as Data)
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
return newJPEG
|
|
1203
|
+
}
|
|
1204
|
+
|
|
986
1205
|
func addGPSMetadata(to image: UIImage, location: CLLocation) {
|
|
987
1206
|
guard let jpegData = image.jpegData(compressionQuality: 1.0),
|
|
988
1207
|
let source = CGImageSourceCreateWithData(jpegData as CFData, nil),
|
|
@@ -855,12 +855,15 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
855
855
|
let quality = call.getFloat("quality", 85)
|
|
856
856
|
let saveToGallery = call.getBool("saveToGallery", false)
|
|
857
857
|
let withExifLocation = call.getBool("withExifLocation", false)
|
|
858
|
+
let embedTimestamp = call.getBool("embedTimestamp", false) ?? false
|
|
859
|
+
let embedLocationRequested = call.getBool("embedLocation", false) ?? false
|
|
860
|
+
let effectiveEmbedLocation = (withExifLocation ?? false) && embedLocationRequested
|
|
858
861
|
let width = call.getInt("width")
|
|
859
862
|
let height = call.getInt("height")
|
|
860
863
|
|
|
861
864
|
print("[CameraPreview] Raw parameter values - width: \(String(describing: width)), height: \(String(describing: height))")
|
|
862
865
|
|
|
863
|
-
print("[CameraPreview] Capture params - quality: \(quality), saveToGallery: \(saveToGallery), withExifLocation: \(withExifLocation), width: \(width ?? -1), height: \(height ?? -1)")
|
|
866
|
+
print("[CameraPreview] Capture params - quality: \(quality), saveToGallery: \(saveToGallery), withExifLocation: \(withExifLocation ?? false), embedTimestamp: \(embedTimestamp), embedLocation: \(effectiveEmbedLocation) (requested=\(embedLocationRequested)), width: \(width ?? -1), height: \(height ?? -1)")
|
|
864
867
|
print("[CameraPreview] Current location: \(self.currentLocation?.description ?? "nil")")
|
|
865
868
|
// Safely read frame from main thread for logging
|
|
866
869
|
let (previewWidth, previewHeight): (CGFloat, CGFloat) = {
|
|
@@ -877,7 +880,8 @@ public class CameraPreview: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelega
|
|
|
877
880
|
}()
|
|
878
881
|
print("[CameraPreview] Preview dimensions: \(previewWidth)x\(previewHeight)")
|
|
879
882
|
|
|
880
|
-
|
|
883
|
+
let gpsForThisCapture = (withExifLocation ?? false) ? self.currentLocation : nil
|
|
884
|
+
self.cameraController.captureImage(width: width, height: height, quality: quality, gpsLocation: gpsForThisCapture, embedTimestamp: embedTimestamp, embedLocation: effectiveEmbedLocation) { (image, originalPhotoData, _, error) in
|
|
881
885
|
print("[CameraPreview] captureImage callback received")
|
|
882
886
|
DispatchQueue.main.async {
|
|
883
887
|
print("[CameraPreview] Processing capture on main thread")
|