Skip to content

Commit

Permalink
fix: image returnableOutputType for base64
Browse files Browse the repository at this point in the history
  • Loading branch information
numandev1 committed Sep 23, 2023
1 parent 482c070 commit e98d144
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions ios/Image/ImageCompressor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,19 @@ class ImageCompressor {
if let img = UIGraphicsGetImageFromCurrentImageContext() {
let imageData = img.jpegData(compressionQuality: compressionQuality)
UIGraphicsEndImageContext()
let filePath = Utils.generateCacheFilePath(outputExtension)
do {
try imageData?.write(to: URL(fileURLWithPath: filePath), options: .atomic)
let returnablePath = ImageCompressor.makeValidUri(filePath)
return returnablePath
} catch {
exception = NSException(name: NSExceptionName(rawValue: "file_error"), reason: "Error writing file", userInfo: nil)
exception?.raise()
let isBase64 = options.returnableOutputType == .rbase64
if isBase64 {
return imageData!.base64EncodedString(options: [])
} else {
let filePath = Utils.generateCacheFilePath(outputExtension)
do {
try imageData?.write(to: URL(fileURLWithPath: filePath), options: .atomic)
let returnablePath = ImageCompressor.makeValidUri(filePath)
return returnablePath
} catch {
exception = NSException(name: NSExceptionName(rawValue: "file_error"), reason: "Error writing file", userInfo: nil)
exception?.raise()
}
}
}
} else {
Expand Down

0 comments on commit e98d144

Please sign in to comment.