Skip to content

Commit 3ed816b

Browse files
committed
Fix comments
1 parent d9834cd commit 3ed816b

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ImageEditor.cropImage(uri, cropData).then((url) => {
5454
| `displaySize` | No | Size to which you want to scale the cropped image |
5555
| `resizeMode` | No | Resizing mode to use when scaling the image (iOS only, Android resize mode is always 'cover', Web - no support) **Default value**: 'contain' |
5656
| `quality` | No | The quality of the resulting image, expressed as a value from `0.0` to `1.0`. <br/>The value `0.0` represents the maximum compression (or lowest quality) while the value `1.0` represents the least compression (or best quality).<br/>iOS supports only `JPEG` format, while Android/Web supports both `JPEG`, `WEBP` and `PNG` formats.<br/>**Default value**: (iOS: `1`), (Android: `0.9`) |
57-
| `format` | No | The format of the resulting image, possible values are `jpeg`, `png`, `webp`. <br/> **Default value**: based on the provided image; if value determination is not possible, `jpeg` will be used as a fallback. <br/> `webp` isn't suported by iOS. |
57+
| `format` | No | The format of the resulting image, possible values are `jpeg`, `png`, `webp`. <br/> **Default value**: based on the provided image; if value determination is not possible, `jpeg` will be used as a fallback. <br/> `webp` isn't supported by iOS. |
5858

5959
```ts
6060
cropData: ImageCropData = {

android/src/main/java/com/reactnativecommunity/imageeditor/ImageEditorModuleImpl.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ import kotlinx.coroutines.cancel
4242
import kotlinx.coroutines.isActive
4343
import kotlinx.coroutines.launch
4444

45+
object MimeType {
46+
const val JPEG = "image/jpeg"
47+
const val PNG = "image/png"
48+
const val WEBP = "image/webp"
49+
}
50+
4551
class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) {
4652
private val moduleCoroutineScope = CoroutineScope(Dispatchers.Default)
4753

@@ -153,7 +159,7 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) {
153159
val mimeType = getMimeType(outOptions, format)
154160
val tempFile = createTempFile(reactContext, mimeType)
155161
writeCompressedBitmapToFile(cropped, mimeType, tempFile, quality)
156-
if (mimeType == "image/jpeg") {
162+
if (mimeType == MimeType.JPEG) {
157163
copyExif(reactContext, Uri.parse(uri), tempFile)
158164
}
159165
promise.resolve(Uri.fromFile(tempFile).toString())
@@ -434,13 +440,13 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) {
434440
private fun getMimeType(outOptions: BitmapFactory.Options, format: String?): String {
435441
val mimeType =
436442
when (format) {
437-
"webp" -> "image/webp"
438-
"png" -> "image/png"
439-
"jpeg" -> "image/jpeg"
443+
"webp" -> MimeType.WEBP
444+
"png" -> MimeType.PNG
445+
"jpeg" -> MimeType.JPEG
440446
else -> outOptions.outMimeType
441447
}
442448
if (mimeType.isNullOrEmpty()) {
443-
return "image/jpeg"
449+
return MimeType.JPEG
444450
}
445451
return mimeType
446452
}
@@ -512,8 +518,8 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) {
512518

513519
private fun getFileExtensionForType(mimeType: String?): String {
514520
return when (mimeType) {
515-
"image/png" -> ".png"
516-
"image/webp" -> ".webp"
521+
MimeType.PNG -> ".png"
522+
MimeType.WEBP -> ".webp"
517523
else -> ".jpg"
518524
}
519525
}
@@ -526,8 +532,8 @@ class ImageEditorModuleImpl(private val reactContext: ReactApplicationContext) {
526532
@Suppress("DEPRECATION") CompressFormat.WEBP
527533
}
528534
return when (mimeType) {
529-
"image/png" -> CompressFormat.PNG
530-
"image/webp" -> webpCompressFormat
535+
MimeType.PNG -> CompressFormat.PNG
536+
MimeType.WEBP -> webpCompressFormat
531537
else -> CompressFormat.JPEG
532538
}
533539
}

0 commit comments

Comments
 (0)