react-native-image-converter
Convert image files into different formats, as well as into their Base64 encoding, especially helpful for uploading image files saved via the camera.
Getting Started
$ npm install --save git+https://git@github.com/voxmarkets/react-native-image-converter
Mostly Automatic Installation
$ react-native link react-native-image-converter
Manual Installation (for the adventurous)
iOS
- 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
)
Android (coming soon!)
- 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')
Usage
import RNImageConverter from 'react-native-image-converter';
Get Image as PNG
RNImageConverter.getPNG(myFile, (newFile) => {
console.log(newFile);
//4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsND...
});
Get Image as JPEG
RNImageConverter.getJPEG(myFile, (newFile) => {
console.log(newFile);
//4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsND...
});