GithubHelp home page GithubHelp logo

fulll / react-native-perspective-image-cropper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from michaelvilleneuve/react-native-perspective-image-cropper

2.0 1.0 0.0 80.51 MB

Perform custom crop, resizing and perspective correction ๐Ÿ“๐Ÿ–ผ

License: MIT License

Java 98.38% JavaScript 1.16% Objective-C 0.01% Objective-C++ 0.28% Ruby 0.07% Makefile 0.10%

react-native-perspective-image-cropper's Introduction

React Native perspective image cropper ๐Ÿ“๐Ÿ–ผ

A component that allows you to perform custom image crop and perspective correction !

Demo image

Designed to work with React Native Document Scanner

https://github.com/Michaelvilleneuve/react-native-document-scanner

Demo gif

Installation ๐Ÿš€๐Ÿš€

$ npm install react-native-perspective-image-cropper --save

$ react-native link react-native-perspective-image-cropper

This library uses react-native-svg, you must install it too. See https://github.com/react-native-community/react-native-svg for more infos.

Android Only

If you do not already have openCV installed in your project, add this line to your settings.gradle

include ':openCVLibrary310'
project(':openCVLibrary310').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-perspective-image-cropper/android/openCVLibrary310')

Crop image

  • First get component ref
<CustomCrop ref={ref => (this.customCrop = ref)} />
  • Then call :
this.customCrop.crop();

Props

Props Type Required Description
updateImage Func Yes Returns the cropped image and the coordinates of the cropped image in the initial photo
rectangleCoordinates Object see usage No Object to predefine an area to crop (an already detected image for example)
initialImage String Yes Base64 encoded image you want to be cropped
height Number Yes Height of the image (will probably disappear in the future
width Number Yes Width of the image (will probably disappear in the future
overlayColor String No Color of the cropping area overlay
overlayStrokeColor String No Color of the cropping area stroke
overlayStrokeWidth Number No Width of the cropping area stroke
handlerColor String No Color of the handlers
enablePanStrict Bool No Enable pan on X axis, and Y axis

Usage

import CustomCrop from "react-native-perspective-image-cropper";

class CropView extends Component {
  componentWillMount() {
    Image.getSize(image, (width, height) => {
      this.setState({
        imageWidth: width,
        imageHeight: height,
        initialImage: image,
        rectangleCoordinates: {
          topLeft: { x: 10, y: 10 },
          topRight: { x: 10, y: 10 },
          bottomRight: { x: 10, y: 10 },
          bottomLeft: { x: 10, y: 10 }
        }
      });
    });
  }

  updateImage(image, newCoordinates) {
    this.setState({
      image,
      rectangleCoordinates: newCoordinates
    });
  }

  crop() {
    this.customCrop.crop();
  }

  render() {
    return (
      <View>
        <CustomCrop
          updateImage={this.updateImage.bind(this)}
          rectangleCoordinates={this.state.rectangleCoordinates}
          initialImage={this.state.initialImage}
          height={this.state.imageHeight}
          width={this.state.imageWidth}
          ref={ref => (this.customCrop = ref)}
          overlayColor="rgba(18,190,210, 1)"
          overlayStrokeColor="rgba(20,190,210, 1)"
          handlerColor="rgba(20,150,160, 1)"
          enablePanStrict={false}
        />
        <TouchableOpacity onPress={this.crop.bind(this)}>
          <Text>CROP IMAGE</Text>
        </TouchableOpacity>
      </View>
    );
  }
}

react-native-perspective-image-cropper's People

Contributors

benjmic avatar michaelvilleneuve avatar tskorupka avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.