Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cropped image is different from the cropping window #22

Closed
saurabhsbora opened this issue Feb 7, 2020 · 14 comments
Closed

Cropped image is different from the cropping window #22

saurabhsbora opened this issue Feb 7, 2020 · 14 comments

Comments

@saurabhsbora
Copy link

Sometimes the image is cropped correctly and sometimes not. I noticed it happens largely when the file size is greater than 1MB.

@ggunti
Copy link
Owner

ggunti commented Mar 5, 2020

I did not meet this problem yet. Please provide more informations like platform, version, a reproducible demo.

@saurabhsbora
Copy link
Author

saurabhsbora commented Mar 9, 2020

@ggunti

Environment

react-native-cli: 2.0.1
react-native: 0.61.4
react-native-amazing-cropper: ^0.1.0
react-native-image-rotate: ^2.1.0
@react-native-community/image-editor: ^2.2.0
VSCode
Windows 10
Android

Description

Cropped Image is different from what is seen in the cropping window

InkedScreenshot_20200309-210910_LI
InkedInkedScreenshot_20200309-210921_LI

Code Snippet

image

As you can see it automatically cropped the image from the first part even though I didn't even move the cropping window.
It is happening for some of the images, although I am not getting the exact criteria.

@Atharva13
Copy link

Yes I am also facing the same issue @ggunti

@ahmed-ismail-nt
Copy link

Hit this bug yesterday on an Android 9 device.
Android/iOS emulator/simulator is fine.

"react-native": "^0.61.5"
"@react-native-community/image-editor": "^2.2.0"
"react-native-image-rotate": "^2.1.0"

But, I've also updated the react-native-image-rotate code so that it can compile.

I have a hunch that it may be related to the image orientation.
For example, the image claim to be vertically (portrait) oriented in the exif data but the actual data is horizontally (landscape) oriented.
This is a possible side-effect of using RNCamera without fixOrientation (on Android).
This is just unverified conjecture at this point.

@saurabhsbora
Copy link
Author

saurabhsbora commented Mar 21, 2020

@AGIsmail Thanks for the information.
The image which I had shown in the above screenshot was selected using a picker.
I had faced issues using images from both sources i.e camera & picker.
I will try to look in the code, if possible could you also share the changes that you have made in react-native-image-rotate.

@ahmed-ismail-nt
Copy link

ahmed-ismail-nt commented Mar 21, 2020

Hey @enthussb
It's basically just the android build.gradle and iOS ImageRotateModule.m files.

For the former, this should be sufficient.

@saurabhsbora
Copy link
Author

@AGIsmail Okay, thanks!

@ggunti
Copy link
Owner

ggunti commented Mar 28, 2020

So, as I understand, the react-native-image-rotate library is buggy. Do you know a better library for rotation which could be used to replace react-native-image-rotate? (excepting expo-image-manipulator, because it is expo dependent)

@ahmed-ismail-nt
Copy link

ahmed-ismail-nt commented Apr 13, 2020

I haven't looked into it too deeply but I do know that react-native-image-crop-picker implements image rotation using the uCrop library.

uCrop is quite robust, but it is for Android only.
Using uCrop would effectively turn this library into a clone/fork of react-native-image-crop-picker with the same limitations (e.g., iOS would not have the image rotation feature).

Perhaps the better idea is for us to fix react-native-image rotate if there's enough support/demand from the community?

EDIT: Did you trace the cause of the cropping image issue to react-native-image-rotate? Or should we continue the image-rotation discussion seperately in issue #24 ?

@AdamSheaHewett
Copy link

AdamSheaHewett commented May 5, 2020

This happens because images taken by phones always have Landscape dimensions, even if taken in Portrait mode. In other words, the width will always be greater than the height, yet for portrait it should be the opposite.

Usually this isn't a problem because most image viewers respect the image's metadata, which specifies orientation (More info).

Solution:

Swap width and height and erase the metadata.

Example:

import ImageResizer from 'react-native-image-resizer';
...
ImageResizer.createResizedImage(image.uri, image.height, image.width, image.mimeType, 100, 0, undefined, false)
    .then((response) => {
            console.log('Resized image in cache', response.uri);
     })
     .catch((err) => {
            console.log('Error resizing image', err);
     });

To determine if it was taken in Portrait mode, check EXIF in metadata. There are libraries for it.

@lid3rs
Copy link

lid3rs commented Dec 1, 2020

You can try this:

import {Image} from 'react-native';

// data is the image object from camera
await Image.getSize(data.uri, (width, height) => {
        data.width = width;
        data.height = height;
      });

@allisson-lima
Copy link

@ggunti solution found?

@ggunti
Copy link
Owner

ggunti commented Sep 15, 2022

For cropping is used @react-native-community/image-editor under the hood.
Check this: callstack/react-native-image-editor#54

@ggunti
Copy link
Owner

ggunti commented Sep 15, 2022

It should be fixed in v0.2.3. Please do not forget to revisit the installation steps (README file) because an another dependency was added: @bam.tech/react-native-image-resizer

@ggunti ggunti closed this as completed Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants