GithubHelp home page GithubHelp logo

simonbuerger / react-native-simple-image-cropper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from barrsan/react-native-simple-image-cropper

0.0 1.0 0.0 8.79 MB

License: MIT License

JavaScript 12.85% Java 8.50% Ruby 7.64% Objective-C 11.49% Starlark 5.27% TypeScript 54.24%

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

react-native-simple-image-cropper

Simple react-native component for image cropping.

Show Case

showcase showcase

DEMO 1

DEMO 2


Installation

npm i react-native-simple-image-cropper --save

or

yarn add react-native-simple-image-cropper

Installing dependencies

npm i react-native-reanimated react-native-gesture-handler react-native-redash @react-native-community/image-editor --save

or

yarn add react-native-reanimated react-native-gesture-handler react-native-redash @react-native-community/image-editor

Libraries installation details: @react-native-community/image-editor, react-native-gesture-handler, react-native-reanimated, react-native-redash.


Usage

import React from 'react';
import { Dimensions, View, Image, Button } from 'react-native';
import ImageCropper from 'react-native-simple-image-cropper';

const window = Dimensions.get('window');
const w = window.width;

const IMAGE = 'https://picsum.photos/id/48/900/500';

const CROP_AREA_WIDTH = w;
const CROP_AREA_HEIGHT = w;

class App extends React.Component {	
  state = {
    cropperParams: {},
    croppedImage: '',
  };

  setCropperParams = cropperParams => {
    this.setState(prevState => ({
      ...prevState,
      cropperParams,
    }));
  };
  
  handlePress = async () => {
    const { cropperParams } = this.state;

    const cropSize = {
      width: 200,
      height: 200,
    };

    const cropAreaSize = {
      width: CROP_AREA_WIDTH,
      height: CROP_AREA_HEIGHT,
    };

    try {
      const result = await ImageCropper.crop({
        ...cropperParams,
        imageUri: IMAGE,
        cropSize,
        cropAreaSize,
      });
      this.setState(prevState => ({
        ...prevState,
        croppedImage: result,
      }));
    } catch (error) {
      console.log(error);
    }
  };
  
  render() {
    const { croppedImage } = this.state;
    const src = { uri: croppedImage };
    
    return (
      <View>
        <ImageCropper
          imageUri={IMAGE}
          cropAreaWidth={CROP_AREA_WIDTH}
          cropAreaHeight={CROP_AREA_HEIGHT}
          containerColor="black"
          areaColor="black"
          setCropperParams={this.setCropperParams}
        />
        <Button onPress={this.handlePress} title="Crop Image" color="blue" />
        {croppedImage ? (
          <Image source={src} />
        ) : null}
      </View>
    );
  }
}

Area overlay

To add a custom overlay, use the areaOverlay property

<ImageCropper
  ...
  areaOverlay={<Image src={require('./overlay.png')}>}
/>

License

MIT

Thanks for contribution

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

Contributors

alexstrat avatar barrsan avatar dependabot[bot] 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.