react-native-compressor 1.14.0 → 1.15.0
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.
|
@@ -133,11 +133,20 @@ object ImageCompressor {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
fun manualCompressImage(imagePath: String?, options: ImageCompressorOptions, reactContext: ReactApplicationContext?): String? {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
val image = if (options.input === ImageCompressorOptions.InputType.base64) decodeImage(imagePath) else loadImage(imagePath)
|
|
137
|
+
val resizedImage = resize(image, options.maxWidth, options.maxHeight)
|
|
138
|
+
val isBase64 = options.returnableOutputType === ImageCompressorOptions.ReturnableOutputType.base64
|
|
139
|
+
val uri = Uri.parse(imagePath)
|
|
140
|
+
val imagePathNew = uri.path
|
|
141
|
+
var scaledBitmap: Bitmap? = correctImageOrientation(resizedImage, imagePathNew)
|
|
142
|
+
val imageDataByteArrayOutputStream = compress(scaledBitmap, options.output, options.quality, options.disablePngTransparency)
|
|
143
|
+
val compressedImagePath = encodeImage(imageDataByteArrayOutputStream, isBase64, options.output.toString(), imagePath, reactContext)
|
|
144
|
+
if (isCompressedSizeLessThanActualFile(imagePath!!, compressedImagePath)) {
|
|
145
|
+
return compressedImagePath
|
|
146
|
+
} else {
|
|
147
|
+
MediaCache.deleteFile(compressedImagePath!!)
|
|
148
|
+
return slashifyFilePath(imagePath)
|
|
149
|
+
}
|
|
141
150
|
}
|
|
142
151
|
|
|
143
152
|
fun isCompressedSizeLessThanActualFile(sourceFileUrl: String,compressedFileUrl: String?): Boolean {
|
|
@@ -249,20 +258,45 @@ object ImageCompressor {
|
|
|
249
258
|
}
|
|
250
259
|
|
|
251
260
|
fun correctImageOrientation(bitmap: Bitmap?, imagePath: String?): Bitmap? {
|
|
261
|
+
if (bitmap == null || imagePath == null) return bitmap
|
|
262
|
+
|
|
252
263
|
return try {
|
|
253
|
-
val exif = ExifInterface(imagePath
|
|
264
|
+
val exif = ExifInterface(imagePath)
|
|
254
265
|
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
|
|
255
266
|
val matrix = Matrix()
|
|
267
|
+
|
|
256
268
|
when (orientation) {
|
|
257
|
-
ExifInterface.
|
|
258
|
-
ExifInterface.
|
|
259
|
-
|
|
260
|
-
|
|
269
|
+
ExifInterface.ORIENTATION_NORMAL -> return bitmap
|
|
270
|
+
ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> {
|
|
271
|
+
matrix.setScale(-1f, 1f)
|
|
272
|
+
}
|
|
273
|
+
ExifInterface.ORIENTATION_ROTATE_180 -> {
|
|
274
|
+
matrix.setRotate(180f)
|
|
275
|
+
}
|
|
276
|
+
ExifInterface.ORIENTATION_FLIP_VERTICAL -> {
|
|
277
|
+
matrix.setScale(1f, -1f)
|
|
278
|
+
}
|
|
279
|
+
ExifInterface.ORIENTATION_TRANSPOSE -> {
|
|
280
|
+
matrix.setRotate(90f)
|
|
281
|
+
matrix.postScale(-1f, 1f)
|
|
282
|
+
}
|
|
283
|
+
ExifInterface.ORIENTATION_ROTATE_90 -> {
|
|
284
|
+
matrix.setRotate(90f)
|
|
285
|
+
}
|
|
286
|
+
ExifInterface.ORIENTATION_TRANSVERSE -> {
|
|
287
|
+
matrix.setRotate(-90f)
|
|
288
|
+
matrix.postScale(-1f, 1f)
|
|
289
|
+
}
|
|
290
|
+
ExifInterface.ORIENTATION_ROTATE_270 -> {
|
|
291
|
+
matrix.setRotate(-90f)
|
|
292
|
+
}
|
|
293
|
+
else -> return bitmap
|
|
261
294
|
}
|
|
262
|
-
|
|
295
|
+
|
|
296
|
+
Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
|
|
263
297
|
} catch (e: IOException) {
|
|
264
298
|
e.printStackTrace()
|
|
265
|
-
bitmap
|
|
299
|
+
bitmap
|
|
266
300
|
}
|
|
267
301
|
}
|
|
268
302
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-compressor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"description": "Compress Image, Video, and Audio same like Whatsapp & Auto/Manual Compression | Background Upload | Download File | Create Video Thumbnail",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|