-
Notifications
You must be signed in to change notification settings - Fork 63
What is the best way to get this library to work with perspective image cropper #60
Comments
Did you find any solution @rosenexpend . I also want to know this. |
I'm not 100% familiar with Use the latest detected coordinates from your state (in the complete example for this project, this is You will most likely need to convert the If the aspect ratios are different, you will need to map them to a new aspect ratio. Basically you need to push out either the width or the height to match while also adjusting the coordinates to match. (I think you can simply just add the change in width to the X coordinates for example). Note: I've considered extracting my cropping/transform code in this package into a callable function from JS so that you could run the crop from javascript yourself. This would allow devs to build a perspective crop tool themselves, or use a package like the one mentioned to manually adjust the coordinates before cropping. It will take a bit of work to get that working, so I haven't given it the time to build it. |
@humphreyja Thanks! Got it to work with |
When you say it doesn't work, does it not crop the image correctly? Is the image rotated, or is the crop not the right size, etc. For this package: For the perspective image cropper: Just from a quick scan of what they are doing, their iOS code is using an older API (actually one of the reasons why I rebuilt this package). It is missing a parameter that I believe helps scale the coordinates and the image to the same scale. And for their Android stuff, it looks similar to mine (they have this weird scaling thing they do which makes absolutely no sense 🤦♂️, but the math works out the the same). I suspect what could be happening is that the coordinates came from an image of a different aspect ratio than the final image being passed in. I use this function first to match the aspect ratios, and then this function to scale the coordinates to match the image being cropped. If I were to expose this logic, I would also include those functions as the output photo is almost always much larger than the preview photo. I hope this helps. I might spend 5 mins today to create an experimental pull request that exposes this code as javascript functions so you can give that a try. |
Sorry as I'm digging into this, I've changed my perspective on that code. So actually this package's iOS code and the perspective package's iOS code are essentially the same for cropping the image. Where I could see some big problems with that package is in the returning of the image. After cropping the image it returns that image in a callback as the base64 encoded version of it. That's terrible. Honestly. Basically that means that it could be sending a 200mb image over the javascript bridge. I never bothered with adding a return image type of base64 to this package because I noticed that it makes my phone freeze and crash. It probably only works with the lowest quality jpeg image. I'm throwing together a PR that instead stores the image in the cache folder and instead returns the directory of that changed image. |
@humphreyja On iOS, the cropper of this |
@chunkydonut21 sorry, I spent a few minutes on this the other day and didn't come up with something usable for you unfortunately. I think personally what I would do is actually just fork that project and simply replace the base64 return portion of that package with the file saving approach of this package. For Android, here is the function that is called with the final image(s) and the steps I take to save them to storage before returning the URI to that saved image. https://github.com/HarvestProfit/react-native-rectangle-scanner/blob/master/android/src/main/java/com/rectanglescanner/views/RNRectangleScannerView.java#L119-L163 Here is the same for iOS: https://github.com/HarvestProfit/react-native-rectangle-scanner/blob/master/ios/RNRectangleScannerView.m#L95-L157 Like I said, everything should work the same, it's just replacing how you interact with the image. If you get something solid working, be sure to share it as this is definitely something that people would like! |
@chunkydonut21 Yes, I made a working prototype version though it is with a local version of the |
Hi,
I am trying to do perspective image cropping once an image is captured. The rectangle coordinates would be used as the overlay. I have tried with the
react-native-perspective-image-cropper
but cannot make the crop actually work. Is there another option for perspective image cropping that can be recommended or a working example ofreact-native-rectangle-scanner
and ``react-native-perspective-image-cropper`? Thank you.The text was updated successfully, but these errors were encountered: