Skip to content

Commit 427631a

Browse files
authored
Merge pull request #191 from numandev1/fix/image-returnableOutputType
fix: image returnableOutputType for base64
2 parents 482c070 + e98d144 commit 427631a

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

ios/Image/ImageCompressor.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,19 @@ class ImageCompressor {
259259
if let img = UIGraphicsGetImageFromCurrentImageContext() {
260260
let imageData = img.jpegData(compressionQuality: compressionQuality)
261261
UIGraphicsEndImageContext()
262-
let filePath = Utils.generateCacheFilePath(outputExtension)
263-
do {
264-
try imageData?.write(to: URL(fileURLWithPath: filePath), options: .atomic)
265-
let returnablePath = ImageCompressor.makeValidUri(filePath)
266-
return returnablePath
267-
} catch {
268-
exception = NSException(name: NSExceptionName(rawValue: "file_error"), reason: "Error writing file", userInfo: nil)
269-
exception?.raise()
262+
let isBase64 = options.returnableOutputType == .rbase64
263+
if isBase64 {
264+
return imageData!.base64EncodedString(options: [])
265+
} else {
266+
let filePath = Utils.generateCacheFilePath(outputExtension)
267+
do {
268+
try imageData?.write(to: URL(fileURLWithPath: filePath), options: .atomic)
269+
let returnablePath = ImageCompressor.makeValidUri(filePath)
270+
return returnablePath
271+
} catch {
272+
exception = NSException(name: NSExceptionName(rawValue: "file_error"), reason: "Error writing file", userInfo: nil)
273+
exception?.raise()
274+
}
270275
}
271276
}
272277
} else {

0 commit comments

Comments
 (0)