Giter Site home page Giter Site logo

halzahrani79 / react-native-asset-resize-to-base64 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tbouder/react-native-asset-resize-to-base64

0.0 1.0 0.0 10.07 MB

Module for React Native to resize and tranform to base64 an asset image

License: MIT License

JavaScript 1.26% Python 0.29% Java 95.68% Objective-C 2.77%

react-native-asset-resize-to-base64's Introduction

react-native-asset-resize-to-base64

This react-native module allows you to get an asset image with CameraRoll (returns an url like this : "assets-library://asset/asset.JPG?id=ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED&ext=JPG"), to resize and transform it to base64 string with NativeModules.RNAssetResizeToBase64.assetToResizedBase64 and then, to upload it with fetch. You can find an example to test it.

The function takes 3 arguments:

  1. The assetUrl
  2. The new width
  3. The new Height

The function return 1 callback with 2 arguments:

  1. err for errors
  2. base64, the base64 string of the resized image

Installation (auto)

  1. npm i react-native-asset-resize-to-base64 --save.
  2. react-native link react-native-asset-resize-to-base64
  3. Import in your file
import {NativeModules} from 'react-native';
  1. Use it
NativeModules.RNAssetResizeToBase64.assetToResizedBase64(url, 500, 500, (err, base64) => console.log(base64))

IOS (manual)

  • Open XCode
  • In the XCode's "Project navigator", right click on your project's Libraries folder โžœ Add Files to <...>
  • Go to node_modules/react-native-asset-resize-to-base64/ios/ and add RNAssetResizeToBase64.xcodeproj
  • In the XCode's "Project navigator", select click on your project's name and add libRNAssetResizeToBase64.a under 'Link Binary with Libraries' in your project's 'Build Phases'

ANDROID (manual)

  • In /android/settings.gradle, add this :
include ':react-native-asset-resize-to-base64'
project(':react-native-asset-resize-to-base64').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-asset-resize-to-base64/android')
  • In /android/app/src/main/java/com//MainApplication.java, add this :
import RNAssetResizeToBase64.RNAssetResizeToBase64Package;
[...]
@Override
	protected List<ReactPackage> getPackages() {
		return Arrays.<ReactPackage>asList(
			new MainReactPackage(),
            new RNAssetResizeToBase64Package(),
            [...]
		);
	}

Example from scratch with access to the user gallery

  1. react-native init example
  2. cd example
  3. npm i react-native-asset-resize-to-base64 --save
  4. react-native link react-native-asset-resize-to-base64
  5. add <You_app>/node_modules/react-native/Libraries/CameraRoll/RCTCameraRoll.xcodeproj to your project (in Xcode, <Your_app> in Libraries)
  6. add libRCTCameraRoll.a (Xcode > Libraries > RCTCameraRoll.xcodeproj > Products > libRCTCameraRoll.a) to your project's Build Phases under "Link Binary With Libraries"
  7. add, in Info.plist, the NSPhotoLibraryUsageDescription key with a string (why do you want to access the user gallery)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.