Giter Club home page Giter Club logo

expo-image-editor's Introduction

๐ŸŒ Expo Image Editor

A super simple image cropping and rotation tool for Expo that runs on iOS, Android and Web!

Screenshot_20201013-161416 Screenshot_20201013-161447 Screenshot_20201013-161347

Check out the demo on Netlify here

Installation

To get started install the package in your Expo project by running:

yarn add expo-image-editor

or

npm i expo-image-editor

Usage

The package exports a single component ImageEditor that can be placed anywhere in your project. This renders a modal that then returns the editing result when it is dismissed.

// ...
import { ImageEditor } from "expo-image-editor";

function App() {
  const [imageUri, setImageUri] = useState(undefined);

  const [editorVisible, setEditorVisible] = useState(false);

  const selectPhoto = async () => {
    // Get the permission to access the camera roll
    const response = await ImagePicker.requestCameraRollPermissionsAsync();
    // If they said yes then launch the image picker
    if (response.granted) {
      const pickerResult = await ImagePicker.launchImageLibraryAsync();
      // Check they didn't cancel the picking
      if (!pickerResult.cancelled) {
        launchEditor(pickerResult.uri);
      }
    } else {
      // If not then alert the user they need to enable it
      Alert.alert(
        "Please enable camera roll permissions for this app in your settings."
      );
    }
  };

  const launchEditor = (uri: string) => {
    // Then set the image uri
    setImageUri(uri);
    // And set the image editor to be visible
    setEditorVisible(true);
  };

  return (
    <View>
      <Image
        style={{ height: 300, width: 300 }}
        source={{ uri: imageData.uri }}
      />
      <Button title="Select Photo" onPress={() => selectPhoto()} />
      <ImageEditor
        visible={editorVisible}
        onCloseEditor={() => setEditorVisible(false)}
        imageUri={imageUri}
        fixedCropAspectRatio={16 / 9}
        lockAspectRatio={aspectLock}
        minimumCropDimensions={{
          width: 100,
          height: 100,
        }}
        onEditingComplete={(result) => {
          setImageData(result);
        }}
        mode="full"
      />
    </View>
  );
}

Props

Name Type Description
visible boolean Whether the editor should be visible or not.
asView boolean If true this will remove the modal wrapper and return the image editor in a regular <View />
mode string Which mode to use the editor in can be either full or crop-only.
onCloseEditor function Callback when the editor is dimissed - use this to set hide the editor.
imageUri string The uri of the image to be edited
fixedCropAspectRatio number The starting aspect ratio of the cropping window.
lockAspectRatio boolean Whether the cropping window should maintain this aspect ratio or not.
minimumCropDimensions object An object of {width, height} specifying the minimum dimensions of the crop window.
onEditingComplete function function that will return the result of the image editing which is an object identical to imageData
throttleBlur boolean Whether to throttle the WebGL update of the blur while adjusting (defaults to false) - useful to set to true on lower performance devices
allowedTransformOperations string[] Which transform operations you want to exclusively allow to be used. Can include crop and rotate e.g. ['crop'] to only allow cropping
allowedAdjustmentOperations string[] Which image adjustment operations you want to exclusively allow to be used. Only blur can be specified at the minute e.g. ['blur'] yo only allow blur as an image adjustment

expo-image-editor's People

Contributors

thomas-coldwell avatar dependabot[bot] 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.