tawachan / expo-image-crop

Crop and rotate image without detach your expo project!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expo image manipulator

Multi plataform 🚀





npm version npm version npm version

Open on your device!

Crop and rotate image without detach your expo project!

Expo.ImageManipulator is only a API without a UI, so you have to build your own UI on top of it, or choose detach your project to use third party linked packages, witch is no so good because a pure javascript Expo project is marvelous!

PRs are welcome...

Example

import React from 'react'
import { Dimensions, Button, ImageBackground } from 'react-native'
import { ImageManipulator } from 'expo-image-crop'

export default class App extends React.Component {
  state = {
      isVisible: false,
      uri: 'https://i.pinimg.com/originals/39/42/a1/3942a180299d5b9587c2aa8e09d91ecf.jpg',
  }
  onToggleModal = () => {
      const { isVisible } = this.state
      this.setState({ isVisible: !isVisible })
  }
  render() {
      const { uri, isVisible } = this.state
      const { width, height } = Dimensions.get('window')
      return (
          <ImageBackground
              resizeMode="contain"
              style={{
                  justifyContent: 'center', padding: 20, alignItems: 'center', height, width, backgroundColor: 'black',
              }}
              source={{ uri }}
          >
              <Button title="Open Image Editor" onPress={() => this.setState({ isVisible: true })} />
              <ImageManipulator
                  photo={{ uri }}
                  isVisible={isVisible}
                  onPictureChoosed={uriM => this.setState({ uri: uriM })}
                  onToggleModal={this.onToggleModal}
              />
          </ImageBackground>
      )
  }
}

Props

  • isVisible: Bool - Show or hide modal with image manipulator UI
  • onPictureChoosed: function - Callback where is passed image edited as parameter
  • photo: object
    • uri: string - uri of image to be edited
  • onToggleModal: function - Callback called when modal is dismissed

Requirements

  • Use it into Expo app (from expo client, Standalone app or ExpoKit app).
  • Because we need to have access to Expo.ImageManipulator
  • Only Expo SDK 25 or Higher

Features

  • Crop and rotate image with Expo.ImageManipulator

If you have some problem open a issue

TO DO

  • [Android / IOS] Detect touches with more precision (Drag / Resizing)
  • [Android / IOS] Better crop mask

About

Crop and rotate image without detach your expo project!

License:MIT License


Languages

Language:JavaScript 100.0%