@capacitor/camera 5.0.9 → 5.0.10
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 +1 -1
- package/ios/Plugin/CameraExtensions.swift +5 -7
- package/ios/Plugin/CameraPlugin.swift +46 -44
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -91,12 +91,10 @@ internal extension UIImage {
|
|
|
91
91
|
targetHeight = maxHeight
|
|
92
92
|
}
|
|
93
93
|
// generate the new image and return
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return
|
|
99
|
-
self.draw(in: CGRect(origin: .zero, size: CGSize(width: targetWidth, height: targetHeight)))
|
|
100
|
-
}
|
|
94
|
+
UIGraphicsBeginImageContextWithOptions(.init(width: targetWidth, height: targetHeight), false, 1.0) // size, opaque and scale
|
|
95
|
+
self.draw(in: .init(origin: .zero, size: .init(width: targetWidth, height: targetHeight)))
|
|
96
|
+
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
|
|
97
|
+
UIGraphicsEndImageContext()
|
|
98
|
+
return resizedImage ?? self
|
|
101
99
|
}
|
|
102
100
|
}
|
|
@@ -246,59 +246,61 @@ extension CameraPlugin: UIImagePickerControllerDelegate, UINavigationControllerD
|
|
|
246
246
|
extension CameraPlugin: PHPickerViewControllerDelegate {
|
|
247
247
|
public func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
|
|
248
248
|
picker.dismiss(animated: true, completion: nil)
|
|
249
|
-
|
|
249
|
+
|
|
250
|
+
guard !results.isEmpty else {
|
|
250
251
|
self.call?.reject("User cancelled photos app")
|
|
251
252
|
return
|
|
252
253
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
guard img.itemProvider.canLoadObject(ofClass: UIImage.self) else {
|
|
258
|
-
self.call?.reject("Error loading image")
|
|
259
|
-
return
|
|
260
|
-
}
|
|
261
|
-
// extract the image
|
|
262
|
-
img.itemProvider.loadObject(ofClass: UIImage.self) { [weak self] (reading, _) in
|
|
263
|
-
if let image = reading as? UIImage {
|
|
264
|
-
var asset: PHAsset?
|
|
265
|
-
if let assetId = img.assetIdentifier {
|
|
266
|
-
asset = PHAsset.fetchAssets(withLocalIdentifiers: [assetId], options: nil).firstObject
|
|
267
|
-
}
|
|
268
|
-
if let processedImage = self?.processedImage(from: image, with: asset?.imageData) {
|
|
269
|
-
images.append(processedImage)
|
|
270
|
-
}
|
|
271
|
-
processedCount += 1
|
|
272
|
-
if processedCount == results.count {
|
|
273
|
-
self?.returnImages(images)
|
|
274
|
-
}
|
|
275
|
-
} else {
|
|
276
|
-
self?.call?.reject("Error loading image")
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
} else {
|
|
282
|
-
guard result.itemProvider.canLoadObject(ofClass: UIImage.self) else {
|
|
283
|
-
self.call?.reject("Error loading image")
|
|
254
|
+
|
|
255
|
+
self.fetchProcessedImages(from: results) { [weak self] processedImageArray in
|
|
256
|
+
guard let processedImageArray else {
|
|
257
|
+
self?.call?.reject("Error loading image")
|
|
284
258
|
return
|
|
285
259
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
260
|
+
|
|
261
|
+
if self?.multiple == true {
|
|
262
|
+
self?.returnImages(processedImageArray)
|
|
263
|
+
} else if var processedImage = processedImageArray.first {
|
|
264
|
+
processedImage.flags = .gallery
|
|
265
|
+
self?.returnProcessedImage(processedImage)
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private func fetchProcessedImages(from pickerResultArray: [PHPickerResult], accumulating: [ProcessedImage] = [], _ completionHandler: @escaping ([ProcessedImage]?) -> Void) {
|
|
271
|
+
func loadImage(from pickerResult: PHPickerResult,_ completionHandler: @escaping (UIImage?) -> Void) {
|
|
272
|
+
let itemProvider = pickerResult.itemProvider
|
|
273
|
+
if itemProvider.canLoadObject(ofClass: UIImage.self) {
|
|
274
|
+
// extract the image
|
|
275
|
+
itemProvider.loadObject(ofClass: UIImage.self) { itemProviderReading, _ in
|
|
276
|
+
completionHandler(itemProviderReading as? UIImage)
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
// extract the image's data representation
|
|
280
|
+
itemProvider.loadDataRepresentation(forTypeIdentifier: UTType.image.identifier) { data, _ in
|
|
281
|
+
guard let data else {
|
|
282
|
+
return completionHandler(nil)
|
|
297
283
|
}
|
|
284
|
+
completionHandler(UIImage(data: data))
|
|
298
285
|
}
|
|
299
|
-
self?.call?.reject("Error loading image")
|
|
300
286
|
}
|
|
301
287
|
}
|
|
288
|
+
|
|
289
|
+
guard let currentPickerResult = pickerResultArray.first else { return completionHandler(accumulating) }
|
|
290
|
+
|
|
291
|
+
loadImage(from: currentPickerResult) { [weak self] loadedImage in
|
|
292
|
+
guard let self, let loadedImage else { return completionHandler(nil) }
|
|
293
|
+
var asset: PHAsset?
|
|
294
|
+
if let assetId = currentPickerResult.assetIdentifier {
|
|
295
|
+
asset = PHAsset.fetchAssets(withLocalIdentifiers: [assetId], options: nil).firstObject
|
|
296
|
+
}
|
|
297
|
+
let newElement = self.processedImage(from: loadedImage, with: asset?.imageData)
|
|
298
|
+
self.fetchProcessedImages(
|
|
299
|
+
from: Array(pickerResultArray.dropFirst()),
|
|
300
|
+
accumulating: accumulating + [newElement],
|
|
301
|
+
completionHandler
|
|
302
|
+
)
|
|
303
|
+
}
|
|
302
304
|
}
|
|
303
305
|
}
|
|
304
306
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/camera",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.10",
|
|
4
4
|
"description": "The Camera API provides the ability to take a photo with the camera or choose an existing one from the photo album.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"publishConfig": {
|
|
80
80
|
"access": "public"
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "f6242b39fa8ba423d1912da5398fb11c2aadfa09"
|
|
83
83
|
}
|