A React-native module it can modify an image by simply.
- resize
- quality
- grayscale
- base64 encoding
- 0.4.1
- React Native >= 0.60
yarn add react-native-image-converter
cd ios && pod install
- React Native <= 0.59
yarn add react-native-image-converter
react-native link react-native-image-converter
- add to yarn package.json
"dependencies": {
"react-native-image-converter": "^0.4.1"
}
import IImageConverter from 'react-native-image-converter'
...
const param = {
path: uri,
grayscale: false, // or true
base64: false, // or true
resizeRatio: 0.8, // 1.0 is origin value
imageQuality: 0.7 // 1.0 is max quality value
}
const { success, errorMsg, imageURI, base64String } = await IImageConverter.convert(param)
- type : string
- description : The absolute path of the local file. (URI)
- type : boolean
- description : If you want to make to grayscale, set true.
- type : boolean
- description : If you want to get image data by base64 encoding, set true.
- type : float
- description : Image resize ratio, between 0.1 to 1.0.
- type : float
- description : Image quality, between 0.1 to 1.0.
- type : boolean
- description : success(true) or failure(false).
- type : string
- description : the message of errors.
- type : string
- description : The absolute path of the edited file. (URI)
- type : string
- description : base64 encoded text data.
- In the Xcode, in the project navigator and right click
Libraries
-> Add Files toyour project name
- Go to
node_modules
->react-native-image-converter
and addRNImageConverter.xcodeproj
- In the Xcode, in the project navigator and select your project. Add
libRNImageConverter.a
to your project'sBuild Phases
->Link Binary With Libraries
- Build & run your project
-
Open
android/app/src/main/java/your project name/MainApplication.java
-
Add
import me.phoboslabs.RNImageConverterPackage;
to the imports line -
Add
new RNImageConverterPackage()
to the list of thegetPackages()
method -
Insert to the
android/settings.gradle
include ':react-native-image-converter' project(':react-native-image-converter').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-converter/android')
-
Insert the line of dependencies block in
android/app/build.gradle
compile project(':react-native-image-converter')
react-native-image-converter
is belongs to the project Illuminati, and distributed MIT license.