goshacmd / react-native-image-converter

Convert Image Files and return them as Base64 Encoded Strings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

  1. In Xcode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-image-converter and add RNImageConverter.xcodeproj
  3. In Xcode, in the project navigator, select your project. Add libRNImageConverter.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)

Android (coming soon!)

  1. 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 the getPackages() method
  1. 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')
    
  2. 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...
});

About

Convert Image Files and return them as Base64 Encoded Strings

License:MIT License


Languages

Language:Java 58.5%Language:Objective-C 23.3%Language:Ruby 15.2%Language:JavaScript 3.0%