react-native-compressor 1.8.11 → 1.8.13
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 +6 -1
- package/android/src/main/java/com/reactnativecompressor/Image/ImageCompressor.kt +56 -23
- package/android/src/main/java/com/reactnativecompressor/Image/ImageCompressorOptions.kt +2 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/MediaCache.kt +15 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/Uploader.kt +1 -12
- package/android/src/main/java/com/reactnativecompressor/Utils/Utils.kt +14 -0
- package/ios/Image/ImageCompressor.swift +53 -41
- package/ios/Image/ImageCompressorOptions.swift +3 -0
- package/ios/Utils/MediaCache.swift +20 -0
- package/ios/Utils/Utils.swift +20 -0
- package/lib/commonjs/Image/index.js.map +1 -1
- package/lib/commonjs/utils/Uploader.js +2 -2
- package/lib/commonjs/utils/Uploader.js.map +1 -1
- package/lib/module/Image/index.js.map +1 -1
- package/lib/module/utils/Uploader.js +1 -1
- package/lib/module/utils/Uploader.js.map +1 -1
- package/lib/typescript/Image/index.d.ts +4 -0
- package/lib/typescript/Image/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Image/index.tsx +4 -0
- package/src/utils/Uploader.tsx +1 -1
package/README.md
CHANGED
|
@@ -362,7 +362,12 @@ await clearCache(); // this will clear cache of thumbnails cache directory
|
|
|
362
362
|
|
|
363
363
|
- ###### `output: OutputType` (default: jpg)
|
|
364
364
|
|
|
365
|
-
|
|
365
|
+
The quality modifier for the `JPEG` file format, can be specified when output is `PNG` but will be ignored. if you wanna apply quality modifier then you can enable `disablePngTransparency:true`,
|
|
366
|
+
**Note:** if you png image have no transparent background then enable `disablePngTransparency:true` modifier is recommended
|
|
367
|
+
|
|
368
|
+
- ###### `disablePngTransparency: boolean` (default: false)
|
|
369
|
+
|
|
370
|
+
when user add `output:'png'` then by default compressed image will have transparent background, and quality will be ignored, if you wanna apply quality then you have to disablePngTransparency like `disablePngTransparency:true`, it will convert transparent background to white
|
|
366
371
|
|
|
367
372
|
- ###### `returnableOutputType: ReturnableOutputType` (default: uri)
|
|
368
373
|
Can be either `uri` or `base64`, defines the Returnable output image format.
|
|
@@ -10,7 +10,9 @@ import android.media.ExifInterface
|
|
|
10
10
|
import android.net.Uri
|
|
11
11
|
import android.util.Base64
|
|
12
12
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
13
|
+
import com.reactnativecompressor.Utils.MediaCache
|
|
13
14
|
import com.reactnativecompressor.Utils.Utils.generateCacheFilePath
|
|
15
|
+
import com.reactnativecompressor.Utils.Utils.slashifyFilePath
|
|
14
16
|
import java.io.ByteArrayOutputStream
|
|
15
17
|
import java.io.File
|
|
16
18
|
import java.io.FileOutputStream
|
|
@@ -71,20 +73,20 @@ object ImageCompressor {
|
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
fun resize(image: Bitmap, maxWidth: Int, maxHeight: Int): Bitmap {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
76
|
+
val size = findActualSize(image, maxWidth, maxHeight)
|
|
77
|
+
val scaledImage = Bitmap.createBitmap(size.width, size.height, Bitmap.Config.ARGB_8888)
|
|
78
|
+
val scaleMatrix = Matrix()
|
|
79
|
+
val canvas = Canvas(scaledImage)
|
|
80
|
+
val paint = Paint(Paint.FILTER_BITMAP_FLAG)
|
|
81
|
+
scaleMatrix.setScale(size.scale, size.scale, 0f, 0f)
|
|
82
|
+
paint.isDither = true
|
|
83
|
+
paint.isAntiAlias = true
|
|
84
|
+
paint.isFilterBitmap = true
|
|
85
|
+
canvas.drawBitmap(image, scaleMatrix, paint)
|
|
86
|
+
return scaledImage
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
fun compress(image: Bitmap?, output: ImageCompressorOptions.OutputType, quality: Float): ByteArrayOutputStream {
|
|
89
|
+
fun compress(image: Bitmap?, output: ImageCompressorOptions.OutputType, quality: Float,disablePngTransparency:Boolean): ByteArrayOutputStream {
|
|
88
90
|
var stream = ByteArrayOutputStream()
|
|
89
91
|
if (output === ImageCompressorOptions.OutputType.jpg)
|
|
90
92
|
{
|
|
@@ -92,12 +94,15 @@ object ImageCompressor {
|
|
|
92
94
|
}
|
|
93
95
|
else
|
|
94
96
|
{
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
var bitmap = image
|
|
98
|
+
if(disablePngTransparency)
|
|
99
|
+
{
|
|
100
|
+
image!!.compress(CompressFormat.JPEG, Math.round(100 * quality), stream)
|
|
101
|
+
val byteArray: ByteArray = stream.toByteArray()
|
|
102
|
+
stream=ByteArrayOutputStream()
|
|
103
|
+
bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size)
|
|
104
|
+
}
|
|
105
|
+
bitmap!!.compress(CompressFormat.PNG, 100, stream)
|
|
101
106
|
}
|
|
102
107
|
return stream
|
|
103
108
|
}
|
|
@@ -105,14 +110,36 @@ object ImageCompressor {
|
|
|
105
110
|
fun manualCompressImage(imagePath: String?, options: ImageCompressorOptions, reactContext: ReactApplicationContext?): String? {
|
|
106
111
|
val image = if (options.input === ImageCompressorOptions.InputType.base64) decodeImage(imagePath) else loadImage(imagePath)
|
|
107
112
|
val resizedImage = resize(image, options.maxWidth, options.maxHeight)
|
|
108
|
-
val imageDataByteArrayOutputStream = compress(resizedImage, options.output, options.quality)
|
|
113
|
+
val imageDataByteArrayOutputStream = compress(resizedImage, options.output, options.quality,options.disablePngTransparency)
|
|
109
114
|
val isBase64 = options.returnableOutputType === ImageCompressorOptions.ReturnableOutputType.base64
|
|
110
115
|
return encodeImage(imageDataByteArrayOutputStream, isBase64, options.output.toString(), reactContext)
|
|
111
116
|
}
|
|
112
117
|
|
|
118
|
+
fun isCompressedSizeLessThanActualFile(sourceFileUrl: String,compressedFileUrl: String?): Boolean {
|
|
119
|
+
try {
|
|
120
|
+
val sourceUri = Uri.parse(sourceFileUrl)
|
|
121
|
+
val sourcePath = sourceUri.path
|
|
122
|
+
val sourcefile = File(sourcePath)
|
|
123
|
+
val sizeInBytesForSourceFile = sourcefile.length().toFloat()
|
|
124
|
+
|
|
125
|
+
val compressedUri = Uri.parse(compressedFileUrl)
|
|
126
|
+
val compressedPath = compressedUri.path
|
|
127
|
+
val compressedfile = File(compressedPath)
|
|
128
|
+
val sizeInBytesForcompressedFile = compressedfile.length().toFloat()
|
|
129
|
+
|
|
130
|
+
if(sizeInBytesForcompressedFile<=sizeInBytesForSourceFile)
|
|
131
|
+
{
|
|
132
|
+
return true
|
|
133
|
+
}
|
|
134
|
+
return false
|
|
135
|
+
} catch (exception: OutOfMemoryError) {
|
|
136
|
+
exception.printStackTrace()
|
|
137
|
+
return true
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
113
141
|
fun autoCompressImage(imagePath: String?, compressorOptions: ImageCompressorOptions, reactContext: ReactApplicationContext?): String? {
|
|
114
142
|
var imagePath = imagePath
|
|
115
|
-
val outputExtension = compressorOptions.output.toString()
|
|
116
143
|
val autoCompressMaxHeight = compressorOptions.maxHeight.toFloat()
|
|
117
144
|
val autoCompressMaxWidth = compressorOptions.maxWidth.toFloat()
|
|
118
145
|
val isBase64 = compressorOptions.returnableOutputType === ImageCompressorOptions.ReturnableOutputType.base64
|
|
@@ -152,7 +179,7 @@ object ImageCompressor {
|
|
|
152
179
|
exception.printStackTrace()
|
|
153
180
|
}
|
|
154
181
|
try {
|
|
155
|
-
scaledBitmap = Bitmap.createBitmap(actualWidth, actualHeight, Bitmap.Config.
|
|
182
|
+
scaledBitmap = Bitmap.createBitmap(actualWidth, actualHeight, Bitmap.Config.ARGB_8888)
|
|
156
183
|
} catch (exception: OutOfMemoryError) {
|
|
157
184
|
exception.printStackTrace()
|
|
158
185
|
}
|
|
@@ -169,8 +196,14 @@ object ImageCompressor {
|
|
|
169
196
|
bmp.recycle()
|
|
170
197
|
}
|
|
171
198
|
scaledBitmap = correctImageOrientation(scaledBitmap, imagePath)
|
|
172
|
-
val imageDataByteArrayOutputStream = compress(scaledBitmap, compressorOptions.output, compressorOptions.quality)
|
|
173
|
-
|
|
199
|
+
val imageDataByteArrayOutputStream = compress(scaledBitmap, compressorOptions.output, compressorOptions.quality,compressorOptions.disablePngTransparency)
|
|
200
|
+
val compressedImagePath=encodeImage(imageDataByteArrayOutputStream, isBase64, compressorOptions.output.toString(), reactContext)
|
|
201
|
+
if(isCompressedSizeLessThanActualFile(imagePath!!,compressedImagePath))
|
|
202
|
+
{
|
|
203
|
+
return compressedImagePath
|
|
204
|
+
}
|
|
205
|
+
MediaCache.deleteFile(compressedImagePath!!)
|
|
206
|
+
return slashifyFilePath(imagePath)
|
|
174
207
|
}
|
|
175
208
|
|
|
176
209
|
fun calculateInSampleSize(options: BitmapFactory.Options, reqWidth: Int, reqHeight: Int): Int {
|
|
@@ -32,6 +32,7 @@ class ImageCompressorOptions {
|
|
|
32
32
|
var output = OutputType.jpg
|
|
33
33
|
var uuid: String? = ""
|
|
34
34
|
var returnableOutputType = ReturnableOutputType.uri
|
|
35
|
+
var disablePngTransparency:Boolean = false
|
|
35
36
|
|
|
36
37
|
companion object {
|
|
37
38
|
fun fromMap(map: ReadableMap): ImageCompressorOptions {
|
|
@@ -49,6 +50,7 @@ class ImageCompressorOptions {
|
|
|
49
50
|
"output" -> options.output = OutputType.valueOf(map.getString(key)!!)
|
|
50
51
|
"returnableOutputType" -> options.returnableOutputType = ReturnableOutputType.valueOf(map.getString(key)!!)
|
|
51
52
|
"uuid" -> options.uuid = map.getString(key)
|
|
53
|
+
"disablePngTransparency" -> options.disablePngTransparency = map.getBoolean(key)
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
return options
|
|
@@ -58,4 +58,19 @@ object MediaCache {
|
|
|
58
58
|
}
|
|
59
59
|
completedImagePaths.clear()
|
|
60
60
|
}
|
|
61
|
+
|
|
62
|
+
fun deleteFile(filePath: String) {
|
|
63
|
+
val _filePath = filePath.replace("file://", "")
|
|
64
|
+
val file = File(_filePath)
|
|
65
|
+
|
|
66
|
+
if (file.exists()) {
|
|
67
|
+
if (file.delete()) {
|
|
68
|
+
println("File deleted successfully.")
|
|
69
|
+
} else {
|
|
70
|
+
println("File couldn't be deleted.")
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
println("File not found.")
|
|
74
|
+
}
|
|
75
|
+
}
|
|
61
76
|
}
|
|
@@ -9,6 +9,7 @@ import com.facebook.react.bridge.Arguments
|
|
|
9
9
|
import com.facebook.react.bridge.Promise
|
|
10
10
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
11
11
|
import com.facebook.react.bridge.ReadableMap
|
|
12
|
+
import com.reactnativecompressor.Utils.Utils.slashifyFilePath
|
|
12
13
|
import okhttp3.Call
|
|
13
14
|
import okhttp3.Callback
|
|
14
15
|
import okhttp3.Headers
|
|
@@ -23,7 +24,6 @@ import java.io.File
|
|
|
23
24
|
import java.io.IOException
|
|
24
25
|
import java.net.URLConnection
|
|
25
26
|
import java.util.concurrent.TimeUnit
|
|
26
|
-
import java.util.regex.Pattern
|
|
27
27
|
|
|
28
28
|
class Uploader(private val reactContext: ReactApplicationContext) {
|
|
29
29
|
val TAG = "asyncTaskUploader"
|
|
@@ -86,17 +86,6 @@ class Uploader(private val reactContext: ReactApplicationContext) {
|
|
|
86
86
|
return client
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
private fun slashifyFilePath(path: String?): String? {
|
|
90
|
-
return if (path == null) {
|
|
91
|
-
null
|
|
92
|
-
} else if (path.startsWith("file:///")) {
|
|
93
|
-
path
|
|
94
|
-
} else {
|
|
95
|
-
// Ensure leading schema with a triple slash
|
|
96
|
-
Pattern.compile("^file:/*").matcher(path).replaceAll("file:///")
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
89
|
@Throws(IOException::class)
|
|
101
90
|
private fun createUploadRequest(url: String, fileUriString: String, options: UploaderOptions, decorator: RequestBodyDecorator): Request {
|
|
102
91
|
val fileUri = Uri.parse(slashifyFilePath(fileUriString))
|
|
@@ -15,6 +15,7 @@ import java.io.IOException
|
|
|
15
15
|
import java.net.HttpURLConnection
|
|
16
16
|
import java.net.URL
|
|
17
17
|
import java.util.UUID
|
|
18
|
+
import java.util.regex.Pattern
|
|
18
19
|
|
|
19
20
|
object Utils {
|
|
20
21
|
private const val TAG = "react-native-compessor"
|
|
@@ -134,6 +135,19 @@ object Utils {
|
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
|
|
138
|
+
fun slashifyFilePath(path: String?): String? {
|
|
139
|
+
return if (path == null) {
|
|
140
|
+
null
|
|
141
|
+
} else if (path.startsWith("file:///")) {
|
|
142
|
+
path
|
|
143
|
+
} else if (path.startsWith("/")) {
|
|
144
|
+
path.replaceFirst("^/+".toRegex(), "file:///")
|
|
145
|
+
}else {
|
|
146
|
+
// Ensure leading schema with a triple slash
|
|
147
|
+
Pattern.compile("^file:/*").matcher(path).replaceAll("file:///")
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
137
151
|
fun addLog(log: String) {
|
|
138
152
|
Log.d(AudioCompressor.TAG, log)
|
|
139
153
|
}
|
|
@@ -100,20 +100,40 @@ class ImageCompressor {
|
|
|
100
100
|
}
|
|
101
101
|
return UIImage()
|
|
102
102
|
}
|
|
103
|
+
|
|
104
|
+
static func isCompressedSizeLessThanActualFile(sourceFileUrl: String,compressedFileUrl: String)-> Bool {
|
|
105
|
+
let sourceVideoURL = URL(string: sourceFileUrl)
|
|
106
|
+
let sourcefileSize:Double=Utils.getfileSizeInBytes(forURL:sourceVideoURL!)
|
|
107
|
+
|
|
108
|
+
let compressedVideoURL = URL(string: compressedFileUrl)
|
|
109
|
+
let compressedfileSize:Double=Utils.getfileSizeInBytes(forURL:compressedVideoURL!)
|
|
110
|
+
|
|
111
|
+
if(compressedfileSize<=sourcefileSize)
|
|
112
|
+
{
|
|
113
|
+
return true
|
|
114
|
+
}
|
|
115
|
+
return false
|
|
116
|
+
}
|
|
103
117
|
|
|
104
118
|
|
|
105
|
-
static func
|
|
119
|
+
static func writeImage(_ image: UIImage, output: Int, quality: Float, outputExtension: String, isBase64: Bool,disablePngTransparency:Bool,isEnableAutoCompress:Bool,actualImagePath:String)-> String{
|
|
106
120
|
var data: Data
|
|
107
121
|
var exception: NSException?
|
|
108
|
-
|
|
109
122
|
switch OutputType(rawValue: output)! {
|
|
110
123
|
case .jpg:
|
|
111
124
|
data = image.jpegData(compressionQuality: CGFloat(quality))!
|
|
112
125
|
case .png:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
if(disablePngTransparency)
|
|
127
|
+
{
|
|
128
|
+
data = image.jpegData(compressionQuality: CGFloat(quality))!
|
|
129
|
+
let compressedImage = UIImage(data: data)
|
|
130
|
+
data = compressedImage!.pngData()!
|
|
131
|
+
}
|
|
132
|
+
else
|
|
133
|
+
{
|
|
134
|
+
data=image.pngData()!
|
|
135
|
+
}
|
|
136
|
+
|
|
117
137
|
}
|
|
118
138
|
|
|
119
139
|
if isBase64 {
|
|
@@ -123,17 +143,35 @@ class ImageCompressor {
|
|
|
123
143
|
do {
|
|
124
144
|
try data.write(to: URL(fileURLWithPath: filePath), options: .atomic)
|
|
125
145
|
let returnablePath = makeValidUri(filePath)
|
|
146
|
+
if(isEnableAutoCompress==true)
|
|
147
|
+
{
|
|
148
|
+
if(self.isCompressedSizeLessThanActualFile(sourceFileUrl: actualImagePath,compressedFileUrl: returnablePath))
|
|
149
|
+
{
|
|
150
|
+
return returnablePath
|
|
151
|
+
}
|
|
152
|
+
else
|
|
153
|
+
{
|
|
154
|
+
MediaCache.deleteFile(atPath:returnablePath)
|
|
155
|
+
return actualImagePath
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
126
159
|
return returnablePath
|
|
160
|
+
|
|
127
161
|
} catch {
|
|
128
162
|
exception = NSException(name: NSExceptionName(rawValue: "file_error"), reason: "Error writing file", userInfo: nil)
|
|
129
163
|
exception?.raise()
|
|
130
164
|
}
|
|
131
165
|
}
|
|
132
|
-
|
|
133
166
|
return ""
|
|
134
167
|
}
|
|
135
168
|
|
|
136
169
|
|
|
170
|
+
static func manualCompress(_ image: UIImage, output: Int, quality: Float, outputExtension: String, isBase64: Bool,disablePngTransparency:Bool,actualImagePath:String) -> String {
|
|
171
|
+
return writeImage(image, output: output, quality: quality, outputExtension: outputExtension, isBase64: isBase64, disablePngTransparency: disablePngTransparency,isEnableAutoCompress: false,actualImagePath: actualImagePath)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
137
175
|
static func scaleAndRotateImage(_ image: UIImage) -> UIImage {
|
|
138
176
|
if image.imageOrientation == .up {
|
|
139
177
|
return image
|
|
@@ -215,7 +253,7 @@ class ImageCompressor {
|
|
|
215
253
|
let outputExtension = ImageCompressorOptions.getOutputInString(options.output)
|
|
216
254
|
let resizedImage = ImageCompressor.manualResize(_image, maxWidth: options.maxWidth, maxHeight: options.maxHeight)
|
|
217
255
|
let isBase64 = options.returnableOutputType == .rbase64
|
|
218
|
-
return ImageCompressor.manualCompress(resizedImage, output: options.output.rawValue, quality: options.quality, outputExtension: outputExtension, isBase64: isBase64)
|
|
256
|
+
return ImageCompressor.manualCompress(resizedImage, output: options.output.rawValue, quality: options.quality, outputExtension: outputExtension, isBase64: isBase64,disablePngTransparency: options.disablePngTransparency,actualImagePath: imagePath)
|
|
219
257
|
} else {
|
|
220
258
|
exception = NSException(name: NSExceptionName(rawValue: "unsupported_value"), reason: "Unsupported value type.", userInfo: nil)
|
|
221
259
|
exception?.raise()
|
|
@@ -228,11 +266,11 @@ class ImageCompressor {
|
|
|
228
266
|
static func autoCompressHandler(_ imagePath: String, options: ImageCompressorOptions) -> String {
|
|
229
267
|
var exception: NSException?
|
|
230
268
|
var image = ImageCompressor.loadImage(imagePath)
|
|
231
|
-
|
|
269
|
+
|
|
232
270
|
if var image = image {
|
|
233
271
|
image = ImageCompressor.scaleAndRotateImage(image)
|
|
234
272
|
let outputExtension = ImageCompressorOptions.getOutputInString(options.output)
|
|
235
|
-
|
|
273
|
+
|
|
236
274
|
var actualHeight = image.size.height
|
|
237
275
|
var actualWidth = image.size.width
|
|
238
276
|
let maxHeight: CGFloat = CGFloat(options.maxHeight)
|
|
@@ -240,7 +278,7 @@ class ImageCompressor {
|
|
|
240
278
|
var imgRatio = actualWidth / actualHeight
|
|
241
279
|
let maxRatio = maxWidth / maxHeight
|
|
242
280
|
let compressionQuality: CGFloat = CGFloat(options.quality)
|
|
243
|
-
|
|
281
|
+
|
|
244
282
|
if actualHeight > maxHeight || actualWidth > maxWidth {
|
|
245
283
|
if imgRatio < maxRatio {
|
|
246
284
|
imgRatio = maxHeight / actualHeight
|
|
@@ -255,42 +293,16 @@ class ImageCompressor {
|
|
|
255
293
|
actualWidth = maxWidth
|
|
256
294
|
}
|
|
257
295
|
}
|
|
258
|
-
|
|
296
|
+
|
|
259
297
|
let rect = CGRect(x: 0.0, y: 0.0, width: actualWidth, height: actualHeight)
|
|
260
298
|
UIGraphicsBeginImageContext(rect.size)
|
|
261
299
|
image.draw(in: rect)
|
|
300
|
+
let isBase64 = options.returnableOutputType == .rbase64
|
|
301
|
+
|
|
262
302
|
if let img = UIGraphicsGetImageFromCurrentImageContext() {
|
|
263
|
-
|
|
264
|
-
switch OutputType(rawValue: options.output.rawValue)! {
|
|
265
|
-
case .jpg:
|
|
266
|
-
imageData = img.jpegData(compressionQuality: compressionQuality)!
|
|
267
|
-
case .png:
|
|
268
|
-
imageData = img.jpegData(compressionQuality: compressionQuality)!
|
|
269
|
-
let compressedImage = UIImage(data: imageData)
|
|
270
|
-
imageData = compressedImage!.pngData()!
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
UIGraphicsEndImageContext()
|
|
274
|
-
let isBase64 = options.returnableOutputType == .rbase64
|
|
275
|
-
if isBase64 {
|
|
276
|
-
return imageData.base64EncodedString(options: [])
|
|
277
|
-
} else {
|
|
278
|
-
let filePath = Utils.generateCacheFilePath(outputExtension)
|
|
279
|
-
do {
|
|
280
|
-
try imageData.write(to: URL(fileURLWithPath: filePath), options: .atomic)
|
|
281
|
-
let returnablePath = ImageCompressor.makeValidUri(filePath)
|
|
282
|
-
return returnablePath
|
|
283
|
-
} catch {
|
|
284
|
-
exception = NSException(name: NSExceptionName(rawValue: "file_error"), reason: "Error writing file", userInfo: nil)
|
|
285
|
-
exception?.raise()
|
|
286
|
-
}
|
|
287
|
-
}
|
|
303
|
+
return writeImage(img, output: options.output.rawValue, quality: Float(compressionQuality), outputExtension: outputExtension, isBase64: isBase64, disablePngTransparency: options.disablePngTransparency,isEnableAutoCompress: true,actualImagePath: imagePath)
|
|
288
304
|
}
|
|
289
|
-
} else {
|
|
290
|
-
exception = NSException(name: NSExceptionName(rawValue: "unsupported_value"), reason: "Unsupported value type.", userInfo: nil)
|
|
291
|
-
exception?.raise()
|
|
292
305
|
}
|
|
293
|
-
|
|
294
306
|
return ""
|
|
295
307
|
}
|
|
296
308
|
|
|
@@ -44,6 +44,8 @@ class ImageCompressorOptions: NSObject {
|
|
|
44
44
|
options.parseReturnableOutput(value as? String)
|
|
45
45
|
case "uuid":
|
|
46
46
|
options.uuid = value as? String
|
|
47
|
+
case "disablePngTransparency":
|
|
48
|
+
options.disablePngTransparency = value as? Bool ?? false
|
|
47
49
|
default:
|
|
48
50
|
break
|
|
49
51
|
}
|
|
@@ -65,6 +67,7 @@ class ImageCompressorOptions: NSObject {
|
|
|
65
67
|
var output: OutputType = .jpg
|
|
66
68
|
var returnableOutputType: ReturnableOutputType = .ruri
|
|
67
69
|
var uuid: String?
|
|
70
|
+
var disablePngTransparency: Bool = false
|
|
68
71
|
|
|
69
72
|
override init() {
|
|
70
73
|
super.init()
|
|
@@ -45,4 +45,24 @@ class MediaCache {
|
|
|
45
45
|
completedImagePaths.removeAll()
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
class func deleteFile(atPath filePath: String) {
|
|
50
|
+
let fileManager = FileManager.default
|
|
51
|
+
var _filePath = filePath
|
|
52
|
+
if _filePath.hasPrefix("file://") {
|
|
53
|
+
_filePath = _filePath.replacingOccurrences(of: "file://", with: "")
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if fileManager.fileExists(atPath: _filePath) {
|
|
57
|
+
do {
|
|
58
|
+
try fileManager.removeItem(atPath: _filePath)
|
|
59
|
+
print("File deleted successfully: \(_filePath)")
|
|
60
|
+
} catch {
|
|
61
|
+
print("Error deleting file: \(error.localizedDescription)")
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
print("File not found at path: \(_filePath)")
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
48
68
|
}
|
package/ios/Utils/Utils.swift
CHANGED
|
@@ -107,4 +107,24 @@ class Utils {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
static func getfileSizeInBytes(forURL url: Any) -> Double {
|
|
111
|
+
var fileURL: URL?
|
|
112
|
+
var fileSize: Double = 0.0
|
|
113
|
+
if (url is URL) || (url is String)
|
|
114
|
+
{
|
|
115
|
+
if (url is URL) {
|
|
116
|
+
fileURL = url as? URL
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
fileURL = URL(fileURLWithPath: url as! String)
|
|
120
|
+
}
|
|
121
|
+
var fileSizeValue = 0.0
|
|
122
|
+
try? fileSizeValue = (fileURL?.resourceValues(forKeys: [URLResourceKey.fileSizeKey]).allValues.first?.value as! Double?)!
|
|
123
|
+
if fileSizeValue > 0.0 {
|
|
124
|
+
fileSize = Double(fileSizeValue)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return fileSize
|
|
128
|
+
}
|
|
129
|
+
|
|
110
130
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_Main","require","_utils","_reactNative","base64UrlRegex","ImageCompressEventEmitter","NativeEventEmitter","Compressor","NativeImage","Image","compress","value","options","arguments","length","undefined","Error","subscription","downloadProgress","uuid","uuidv4","addListener","event","data","progress","cleanData","replace","image_compress","remove","_default","exports","default"],"sourceRoot":"../../../src","sources":["Image/index.tsx"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAGA,IAAAE,YAAA,GAAAF,OAAA;AAFA,MAAMG,cAAc,GAAG,6CAA6C;
|
|
1
|
+
{"version":3,"names":["_Main","require","_utils","_reactNative","base64UrlRegex","ImageCompressEventEmitter","NativeEventEmitter","Compressor","NativeImage","Image","compress","value","options","arguments","length","undefined","Error","subscription","downloadProgress","uuid","uuidv4","addListener","event","data","progress","cleanData","replace","image_compress","remove","_default","exports","default"],"sourceRoot":"../../../src","sources":["Image/index.tsx"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAGA,IAAAE,YAAA,GAAAF,OAAA;AAFA,MAAMG,cAAc,GAAG,6CAA6C;AAuDpE,MAAMC,yBAAyB,GAAG,IAAIC,+BAAkB,CAACC,gBAAU,CAAC;AAEpE,MAAMC,WAAW,GAAGD,gBAAU;AAM9B,MAAME,KAAgB,GAAG;EACvBC,QAAQ,EAAE,eAAAA,CAAOC,KAAK,EAAmB;IAAA,IAAjBC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAClC,IAAI,CAACF,KAAK,EAAE;MACV,MAAM,IAAIK,KAAK,CACb,qEACF,CAAC;IACH;IAEA,IAAIC,YAAqC;IACzC,IAAI;MACF,IAAIL,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEM,gBAAgB,EAAE;QAC7B,MAAMC,IAAI,GAAG,IAAAC,aAAM,EAAC,CAAC;QACrB;QACAR,OAAO,CAACO,IAAI,GAAGA,IAAI;QACnBF,YAAY,GAAGZ,yBAAyB,CAACgB,WAAW,CAClD,kBAAkB,EACjBC,KAAU,IAAK;UACd,IAAIA,KAAK,CAACH,IAAI,KAAKA,IAAI,EAAE;YACvBP,OAAO,CAACM,gBAAgB,IACtBN,OAAO,CAACM,gBAAgB,CAACI,KAAK,CAACC,IAAI,CAACC,QAAQ,CAAC;UACjD;QACF,CACF,CAAC;MACH;MAEA,MAAMC,SAAS,GAAGd,KAAK,CAACe,OAAO,CAACtB,cAAc,EAAE,EAAE,CAAC;MACnD,OAAO,MAAMI,WAAW,CAACmB,cAAc,CAACF,SAAS,EAAEb,OAAO,CAAC;IAC7D,CAAC,SAAS;MACR;MACA,IAAIK,YAAY,EAAE;QAChBA,YAAY,CAACW,MAAM,CAAC,CAAC;MACvB;IACF;EACF;AACF,CAAC;AAAC,IAAAC,QAAA,GAEapB,KAAK;AAAAqB,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.backgroundUpload = exports.UploaderHttpMethod = exports.UploadType = void 0;
|
|
7
7
|
var _reactNative = require("react-native");
|
|
8
8
|
var _Main = require("../Main");
|
|
9
|
-
var
|
|
9
|
+
var _index = require("./index");
|
|
10
10
|
const CompressEventEmitter = new _reactNative.NativeEventEmitter(_Main.Compressor);
|
|
11
11
|
let UploadType = /*#__PURE__*/function (UploadType) {
|
|
12
12
|
UploadType[UploadType["BINARY_CONTENT"] = 0] = "BINARY_CONTENT";
|
|
@@ -22,7 +22,7 @@ let UploaderHttpMethod = /*#__PURE__*/function (UploaderHttpMethod) {
|
|
|
22
22
|
}({});
|
|
23
23
|
exports.UploaderHttpMethod = UploaderHttpMethod;
|
|
24
24
|
const backgroundUpload = async (url, fileUrl, options, onProgress) => {
|
|
25
|
-
const uuid = (0,
|
|
25
|
+
const uuid = (0, _index.uuidv4)();
|
|
26
26
|
let subscription;
|
|
27
27
|
try {
|
|
28
28
|
if (onProgress) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_Main","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_Main","_index","CompressEventEmitter","NativeEventEmitter","Compressor","UploadType","exports","UploaderHttpMethod","backgroundUpload","url","fileUrl","options","onProgress","uuid","uuidv4","subscription","addListener","event","data","written","total","Platform","OS","includes","replace","result","upload","method","httpMethod","headers","uploadType","remove"],"sourceRoot":"../../../src","sources":["utils/Uploader.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AADA,MAAMG,oBAAoB,GAAG,IAAIC,+BAAkB,CAACC,gBAAU,CAAC;AAAC,IAEpDC,UAAU,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAAAC,OAAA,CAAAD,UAAA,GAAAA,UAAA;AAAA,IAKVE,kBAAkB,0BAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA;AAAAD,OAAA,CAAAC,kBAAA,GAAAA,kBAAA;AA8BvB,MAAMC,gBAAgB,GAAG,MAAAA,CAC9BC,GAAW,EACXC,OAAe,EACfC,OAAwB,EACxBC,UAAqD,KACpC;EACjB,MAAMC,IAAI,GAAG,IAAAC,aAAM,EAAC,CAAC;EACrB,IAAIC,YAAqC;EACzC,IAAI;IACF,IAAIH,UAAU,EAAE;MACdG,YAAY,GAAGb,oBAAoB,CAACc,WAAW,CAC7C,gBAAgB,EACfC,KAAU,IAAK;QACd,IAAIA,KAAK,CAACJ,IAAI,KAAKA,IAAI,EAAE;UACvBD,UAAU,CAACK,KAAK,CAACC,IAAI,CAACC,OAAO,EAAEF,KAAK,CAACC,IAAI,CAACE,KAAK,CAAC;QAClD;MACF,CACF,CAAC;IACH;IACA,IAAIC,qBAAQ,CAACC,EAAE,KAAK,SAAS,IAAIZ,OAAO,CAACa,QAAQ,CAAC,SAAS,CAAC,EAAE;MAC5Db,OAAO,GAAGA,OAAO,CAACc,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;IAC1C;IACA,MAAMC,MAAM,GAAG,MAAMrB,gBAAU,CAACsB,MAAM,CAAChB,OAAO,EAAE;MAC9CG,IAAI;MACJc,MAAM,EAAEhB,OAAO,CAACiB,UAAU;MAC1BC,OAAO,EAAElB,OAAO,CAACkB,OAAO;MACxBC,UAAU,EAAEnB,OAAO,CAACmB,UAAU;MAC9B,GAAGnB,OAAO;MACVF;IACF,CAAC,CAAC;IACF,OAAOgB,MAAM;EACf,CAAC,SAAS;IACR;IACA,IAAIV,YAAY,EAAE;MAChBA,YAAY,CAACgB,MAAM,CAAC,CAAC;IACvB;EACF;AACF,CAAC;AAACzB,OAAA,CAAAE,gBAAA,GAAAA,gBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Compressor","uuidv4","base64UrlRegex","NativeEventEmitter","ImageCompressEventEmitter","NativeImage","Image","compress","value","options","arguments","length","undefined","Error","subscription","downloadProgress","uuid","addListener","event","data","progress","cleanData","replace","image_compress","remove"],"sourceRoot":"../../../src","sources":["Image/index.tsx"],"mappings":"AAAA,SAASA,UAAU,QAAQ,SAAS;AACpC,SAASC,MAAM,QAAQ,UAAU;AACjC,MAAMC,cAAc,GAAG,6CAA6C;AAEpE,SAASC,kBAAkB,QAAQ,cAAc;
|
|
1
|
+
{"version":3,"names":["Compressor","uuidv4","base64UrlRegex","NativeEventEmitter","ImageCompressEventEmitter","NativeImage","Image","compress","value","options","arguments","length","undefined","Error","subscription","downloadProgress","uuid","addListener","event","data","progress","cleanData","replace","image_compress","remove"],"sourceRoot":"../../../src","sources":["Image/index.tsx"],"mappings":"AAAA,SAASA,UAAU,QAAQ,SAAS;AACpC,SAASC,MAAM,QAAQ,UAAU;AACjC,MAAMC,cAAc,GAAG,6CAA6C;AAEpE,SAASC,kBAAkB,QAAQ,cAAc;AAqDjD,MAAMC,yBAAyB,GAAG,IAAID,kBAAkB,CAACH,UAAU,CAAC;AAEpE,MAAMK,WAAW,GAAGL,UAAU;AAM9B,MAAMM,KAAgB,GAAG;EACvBC,QAAQ,EAAE,eAAAA,CAAOC,KAAK,EAAmB;IAAA,IAAjBC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAClC,IAAI,CAACF,KAAK,EAAE;MACV,MAAM,IAAIK,KAAK,CACb,qEACF,CAAC;IACH;IAEA,IAAIC,YAAqC;IACzC,IAAI;MACF,IAAIL,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEM,gBAAgB,EAAE;QAC7B,MAAMC,IAAI,GAAGf,MAAM,CAAC,CAAC;QACrB;QACAQ,OAAO,CAACO,IAAI,GAAGA,IAAI;QACnBF,YAAY,GAAGV,yBAAyB,CAACa,WAAW,CAClD,kBAAkB,EACjBC,KAAU,IAAK;UACd,IAAIA,KAAK,CAACF,IAAI,KAAKA,IAAI,EAAE;YACvBP,OAAO,CAACM,gBAAgB,IACtBN,OAAO,CAACM,gBAAgB,CAACG,KAAK,CAACC,IAAI,CAACC,QAAQ,CAAC;UACjD;QACF,CACF,CAAC;MACH;MAEA,MAAMC,SAAS,GAAGb,KAAK,CAACc,OAAO,CAACpB,cAAc,EAAE,EAAE,CAAC;MACnD,OAAO,MAAMG,WAAW,CAACkB,cAAc,CAACF,SAAS,EAAEZ,OAAO,CAAC;IAC7D,CAAC,SAAS;MACR;MACA,IAAIK,YAAY,EAAE;QAChBA,YAAY,CAACU,MAAM,CAAC,CAAC;MACvB;IACF;EACF;AACF,CAAC;AAED,eAAelB,KAAK"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NativeEventEmitter, Platform } from 'react-native';
|
|
2
2
|
import { Compressor } from '../Main';
|
|
3
3
|
const CompressEventEmitter = new NativeEventEmitter(Compressor);
|
|
4
|
-
import { uuidv4 } from '
|
|
4
|
+
import { uuidv4 } from './index';
|
|
5
5
|
export let UploadType = /*#__PURE__*/function (UploadType) {
|
|
6
6
|
UploadType[UploadType["BINARY_CONTENT"] = 0] = "BINARY_CONTENT";
|
|
7
7
|
UploadType[UploadType["MULTIPART"] = 1] = "MULTIPART";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","Platform","Compressor","CompressEventEmitter","uuidv4","UploadType","UploaderHttpMethod","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","OS","includes","replace","result","upload","method","httpMethod","headers","uploadType","remove"],"sourceRoot":"../../../src","sources":["utils/Uploader.tsx"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,QAAQ,QAAQ,cAAc;AAE3D,SAASC,UAAU,QAAQ,SAAS;AACpC,MAAMC,oBAAoB,GAAG,IAAIH,kBAAkB,CAACE,UAAU,CAAC;AAC/D,SAASE,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","Platform","Compressor","CompressEventEmitter","uuidv4","UploadType","UploaderHttpMethod","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","OS","includes","replace","result","upload","method","httpMethod","headers","uploadType","remove"],"sourceRoot":"../../../src","sources":["utils/Uploader.tsx"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,QAAQ,QAAQ,cAAc;AAE3D,SAASC,UAAU,QAAQ,SAAS;AACpC,MAAMC,oBAAoB,GAAG,IAAIH,kBAAkB,CAACE,UAAU,CAAC;AAC/D,SAASE,MAAM,QAAQ,SAAS;AAChC,WAAYC,UAAU,0BAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;AAKtB,WAAYC,kBAAkB,0BAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA;AA8B9B,OAAO,MAAMC,gBAAgB,GAAG,MAAAA,CAC9BC,GAAW,EACXC,OAAe,EACfC,OAAwB,EACxBC,UAAqD,KACpC;EACjB,MAAMC,IAAI,GAAGR,MAAM,CAAC,CAAC;EACrB,IAAIS,YAAqC;EACzC,IAAI;IACF,IAAIF,UAAU,EAAE;MACdE,YAAY,GAAGV,oBAAoB,CAACW,WAAW,CAC7C,gBAAgB,EACfC,KAAU,IAAK;QACd,IAAIA,KAAK,CAACH,IAAI,KAAKA,IAAI,EAAE;UACvBD,UAAU,CAACI,KAAK,CAACC,IAAI,CAACC,OAAO,EAAEF,KAAK,CAACC,IAAI,CAACE,KAAK,CAAC;QAClD;MACF,CACF,CAAC;IACH;IACA,IAAIjB,QAAQ,CAACkB,EAAE,KAAK,SAAS,IAAIV,OAAO,CAACW,QAAQ,CAAC,SAAS,CAAC,EAAE;MAC5DX,OAAO,GAAGA,OAAO,CAACY,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;IAC1C;IACA,MAAMC,MAAM,GAAG,MAAMpB,UAAU,CAACqB,MAAM,CAACd,OAAO,EAAE;MAC9CG,IAAI;MACJY,MAAM,EAAEd,OAAO,CAACe,UAAU;MAC1BC,OAAO,EAAEhB,OAAO,CAACgB,OAAO;MACxBC,UAAU,EAAEjB,OAAO,CAACiB,UAAU;MAC9B,GAAGjB,OAAO;MACVF;IACF,CAAC,CAAC;IACF,OAAOc,MAAM;EACf,CAAC,SAAS;IACR;IACA,IAAIT,YAAY,EAAE;MAChBA,YAAY,CAACe,MAAM,CAAC,CAAC;IACvB;EACF;AACF,CAAC"}
|
|
@@ -27,6 +27,10 @@ export type CompressorOptions = {
|
|
|
27
27
|
* The output image type.
|
|
28
28
|
*/
|
|
29
29
|
output?: OutputType;
|
|
30
|
+
/***
|
|
31
|
+
* when user add `output:'png'` then by default compressed image will have transparent background, and quality will be ignored, if you wanna apply quality then you have to disablePngTransparency like `disablePngTransparency:true`, it will convert transparent background to white
|
|
32
|
+
*/
|
|
33
|
+
disablePngTransparency?: boolean;
|
|
30
34
|
/***
|
|
31
35
|
* The output that will return to user.
|
|
32
36
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Image/index.tsx"],"names":[],"mappings":"AAMA,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEzC,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,KAAK,CAAC;AAEvC,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEpD,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAElD,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;OAEG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB;;OAEG;IACH,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C;;OAEG;IACH,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAMF,KAAK,SAAS,GAAG;IACf,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACvE,CAAC;AAEF,QAAA,MAAM,KAAK,EAAE,SAkCZ,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Image/index.tsx"],"names":[],"mappings":"AAMA,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEzC,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,KAAK,CAAC;AAEvC,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEpD,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAElD,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;OAEG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB;;OAEG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;OAEG;IACH,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C;;OAEG;IACH,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAMF,KAAK,SAAS,GAAG;IACf,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACvE,CAAC;AAEF,QAAA,MAAM,KAAK,EAAE,SAkCZ,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
package/package.json
CHANGED
package/src/Image/index.tsx
CHANGED
|
@@ -37,6 +37,10 @@ export type CompressorOptions = {
|
|
|
37
37
|
* The output image type.
|
|
38
38
|
*/
|
|
39
39
|
output?: OutputType;
|
|
40
|
+
/***
|
|
41
|
+
* when user add `output:'png'` then by default compressed image will have transparent background, and quality will be ignored, if you wanna apply quality then you have to disablePngTransparency like `disablePngTransparency:true`, it will convert transparent background to white
|
|
42
|
+
*/
|
|
43
|
+
disablePngTransparency?: boolean;
|
|
40
44
|
/***
|
|
41
45
|
* The output that will return to user.
|
|
42
46
|
*/
|
package/src/utils/Uploader.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { NativeEventEmitter, Platform } from 'react-native';
|
|
|
2
2
|
import type { NativeEventSubscription } from 'react-native';
|
|
3
3
|
import { Compressor } from '../Main';
|
|
4
4
|
const CompressEventEmitter = new NativeEventEmitter(Compressor);
|
|
5
|
-
import { uuidv4 } from '
|
|
5
|
+
import { uuidv4 } from './index';
|
|
6
6
|
export enum UploadType {
|
|
7
7
|
BINARY_CONTENT = 0,
|
|
8
8
|
MULTIPART = 1,
|