Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
feat: heic or heif to jpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
yungblud committed Dec 2, 2020
1 parent e351a5f commit fa38504
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ PODS:
- React-cxxreact (= 0.62.2)
- React-jsi (= 0.62.2)
- React-jsinspector (0.62.2)
- react-native-image-selector (0.1.14):
- react-native-image-selector (0.1.15):
- React
- React-RCTActionSheet (0.62.2):
- React-Core/RCTActionSheetHeaders (= 0.62.2)
Expand Down Expand Up @@ -429,7 +429,7 @@ SPEC CHECKSUMS:
React-jsi: b6dc94a6a12ff98e8877287a0b7620d365201161
React-jsiexecutor: 1540d1c01bb493ae3124ed83351b1b6a155db7da
React-jsinspector: 512e560d0e985d0e8c479a54a4e5c147a9c83493
react-native-image-selector: 196e21b2c85ee4a59f36bb1e9e8d11a0b8a601b4
react-native-image-selector: 0d24ac8a6cae3e58f5e793b57d607161d98beed1
React-RCTActionSheet: f41ea8a811aac770e0cc6e0ad6b270c644ea8b7c
React-RCTAnimation: 49ab98b1c1ff4445148b72a3d61554138565bad0
React-RCTBlob: a332773f0ebc413a0ce85942a55b064471587a71
Expand Down
2 changes: 1 addition & 1 deletion ios/ImageSelector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ extension ImageSelector: UIImagePickerControllerDelegate {
case .camera:
if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
if let rotatedImage = ImageUtil.rotateImage(image: pickedImage) {
if let imageData = rotatedImage.pngData() {
if let imageData = rotatedImage.jpegData(compressionQuality: 1.0) {
var pathDirectory: String? = nil
if let storageOptions = self.options["storageOptions"] as? [String: Any] {
if let path = storageOptions["path"] as? String {
Expand Down
12 changes: 10 additions & 2 deletions ios/ImageUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import Photos

class ImageUtil: NSObject {
static func createCacheFile(imageData: Data, pathDirectory: String?, callback: RCTResponseSenderBlock?) -> [String: Any]? {
guard let jpegImage = UIImage(data: imageData) else {
return nil
}

guard let imageData = jpegImage.jpegData(compressionQuality: 1.0) else {
return nil
}

let fileManager = FileManager.default
if let documentDirectoryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first {
let path = (documentDirectoryPath as NSString).appendingPathComponent(pathDirectory ?? "")
Expand All @@ -24,7 +32,7 @@ class ImageUtil: NSObject {
return nil
}
let uuid: String = UUID().uuidString
let fileName = (uuid as NSString).appendingPathExtension("png") ?? "\(uuid).png"
let fileName = (uuid as NSString).appendingPathExtension("jpeg") ?? "\(uuid).jpeg"
let filePath = (path as NSString).appendingPathComponent(fileName)
fileManager.createFile(atPath: filePath, contents: imageData, attributes: nil)
let base64EncodedString: String = imageData.base64EncodedString()
Expand All @@ -33,7 +41,7 @@ class ImageUtil: NSObject {
"path": filePath,
"uri": "file://\(filePath)",
"fileName": fileName,
"type": "image/png",
"type": "image/jpeg",
"fileSize": imageData.count
]
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-image-selector",
"version": "0.1.14",
"version": "0.1.15",
"description": "image picker native module",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down

0 comments on commit fa38504

Please sign in to comment.