Convert image files into different formats, as well as into their Base64 encoding, especially helpful for uploading image files saved via the camera.
$ npm install --save git+https://[email protected]/voxmarkets/react-native-image-converter
$ react-native link react-native-image-converter
- In Xcode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-image-converter
and addRNImageConverter.xcodeproj
- In Xcode, in the project navigator, select your project. Add
libRNImageConverter.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNImageConverterPackage;
to the imports at the top of the file - Add
new RNImageConverterPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
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 following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-image-converter')
import RNImageConverter from 'react-native-image-converter';
RNImageConverter.getPNG(myFile, (newFile) => {
console.log(newFile);
//4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsND...
});
RNImageConverter.getJPEG(myFile, (newFile) => {
console.log(newFile);
//4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsND...
});