GithubHelp home page GithubHelp logo

react-native-image-cropping's Introduction

Simple react-native image cropping library wrapper around siong1987/TOCropViewController

TOCropViewController

Installation

Supported only on iOS.

Add it to your project

  1. npm install react-native-image-cropping --save
  2. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  3. Go to node_modulesreact-native-image-cropping and add ReactNativeImageCropping.xcodeproj
  4. In XCode, in the project navigator, select your project. Add libReactNativeImageCropping.a to your project's Build PhasesLink Binary With Libraries
  5. Click ReactNativeImageCropping.xcodeproj in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for Header Search Paths and make sure it contains both $(SRCROOT)/../react-native/React and $(SRCROOT)/../../React - mark both as recursive.
  6. Re-run your project (Cmd+R)

Setup trouble?

If you get stuck open an issue. It's the first time I've published react native package and I may have not provided all necessary information.

Usage

Import module

const React = require('react-native');
const {ReactNativeImageCropping} = React.NativeModules;

Crop the image

It is using RCTImageLoader so it should be able to crop any image that react knows how to load / display.

Without aspect ratio restriction:

const originalImage = require('CrazyFlowers.jpg');

ReactNativeImageCropping
	.cropImageWithUrl(originalImage.uri)
    .then(image => {
		//Image is saved in NSTemporaryDirectory!
		//image = {uri, width, height}	
	},
	err => console.log(b));

Lock to specific aspect ratio:

Available aspect ratios:

 - AspectRatioOriginal
 - AspectRatioSquare
 - AspectRatio3x2
 - AspectRatio5x4
 - AspectRatio4x3
 - AspectRatio5x4
 - AspectRatio7x5
 - AspectRatio16x9

Example:

let aspectRatio = ReactNativeImageCropping.AspectRatioSquare;

ReactNativeImageCropping
    .cropImageWithUrlAndAspect(imageUrl, aspectRatio)
    .then(image => {
        //Image is saved in NSTemporaryDirectory!
        //image = {uri, width, height}  
    },
    err => console.log(b));

react-native-image-cropping's People

Contributors

meznaric avatar wehriam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-image-cropping's Issues

Add method to set max/min zoom in the crop box

Could you add a method that also defines the max zoom, something like:

.cropImageWithUrlAndAspectAndMaxZoom(imageUrl, aspectRatio, MaxZoomWidth, MaxZoomHeight)

the idea is that MaxZoomWidth and MaxZoomHeight would be the same as the width and height in the image object (image = { uri, width, height }) that is returned in the then() block after cropping has finished.

Example: When I zoom in with two fingers until I can't zoom any furter and click "Done" the width and height values that are returned in the image object are 24. I would like to set MaxZoomWidth and Height to f.x. 300.

Great work by the way!

Cropper never get opened

I am using this below code:
ReactNativeImageCropping.cropImageWithUrl(uri)
.then((image) => {
//Image is saved in NSTemporaryDirectory!
//image = {uri, width, height}
console.log(image)
}, (err) => console.log(err));

cropping screen or error never shows up

Custom Aspect Ratios?

Is it possible to set a custom aspect ratio. I need to fix the cropping to portrait mode.

how to pass Image path not as url

Hi, this library is really great, it works well with http urls but when i try to pass the camera image path like assets-library or disk path it gave me error. is there any workaround for this issue? or i am doing something wrong? thank you.

How to change the size of the cropper ? to make it a square ?

First of all, thanks so much for the module, I have been building my image cropper from scratch for a week or so, but I stuck at getting the correct crop sizes correct, and than I found your module, it's just so easy 😄

Well, I really need a way to resize the cropper to be like a square ?

Thanks again!

detailed example

Hi could you provide more detailed example on how to use the package?

Add methods to programatically resize/crop/rotate or change quality of the image.

2 people on Facebook requested some extra features.

Proposed methods:

ReactNativeImageCropping.resize(imageUri, newWidth, newHeight);
ReactNativeImageCropping.crop(imageUri, x, y, width, height);
ReactNativeImageCropping.rotate(imageUri, 90); //Degrees should be 90,180, 270 or should we support all?
ReactNativeImageCropping.changeQuality(imageUri, 90); //Quality from 1-100 similar to what JPEG
ReactNativeImageCropping.moveToAlbum(imageUri, albumName);
ReactNativeImageCropping.moveToDocuments(imageUri, filename); //Is this needed?

Idea is that you should always be able to pass in original image object and you will always get back image with image.uri set to path to image in NSTemporaryDirectory. User should then decide where he wants to move it using moveToDocuments or moveToAlbum.

Any thoughts?

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.