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

Are the axis inverted when cropping? #160

Open
frodriguez-hu opened this issue Aug 14, 2024 · 12 comments
Open

Are the axis inverted when cropping? #160

frodriguez-hu opened this issue Aug 14, 2024 · 12 comments
Labels
question Further information is requested

Comments

@frodriguez-hu
Copy link

Ask your Question

I realized that when I modify the x it has impact on the y axis on the final output an viceversa

@frodriguez-hu frodriguez-hu added the question Further information is requested label Aug 14, 2024
@retyui
Copy link
Collaborator

retyui commented Aug 14, 2024

@frodriguez-hu Could you provide an example so I can easy reproduce this issue ?

@frodriguez-hu
Copy link
Author

frodriguez-hu commented Aug 14, 2024

This is what i am doing @retyui :

ImageRN.getSize(`file://${takenPhoto.path}`, async (w, h) => {
        const scaleFactorY = h / windowDimensions.height;
        const scaleFactorX = w / windowDimensions.width;
        try {
          const {
            uri,
            size,
            width: widthH,
            height: heightH,
          } = await ImageEditor.cropImage(`file://${takenPhoto.path}`, {
            offset: {
              x: (y + height / 2) * scaleFactorY,
              y: x * scaleFactorX,
            },
            size: {width: height * scaleFactorY, height: width * scaleFactorX},
            displaySize: {width: 192, height: 192},
          });
          console.log(size, w, h, widthH, heightH);
          setPhoto(uri);
        } catch (e) {
          console.log(e);
        }
      });

I have to invert the axis to make it work

@frodriguez-hu
Copy link
Author

I just have some coordinates on other NxM Dimensions and I want to crop the image with those dimensions

@frodriguez-hu
Copy link
Author

frodriguez-hu commented Aug 14, 2024

@retyui

And also x which is y on the final result, is not cropping on the right position on the transformation I made.

I mean, with inverted axis, this should work:

     const scaleFactorY = h / windowDimensions.height;
        const scaleFactorX = w / windowDimensions.width;
        try {
          const {
            uri,
            size,
            width: widthH,
            height: heightH,
          } = await ImageEditor.cropImage(`file://${takenPhoto.path}`, {
            offset: {
              x: y * scaleFactorY,
              y: x * scaleFactorX,
            },
            size: {width: height * scaleFactorY, height: width * scaleFactorX},
            displaySize: {width: 192, height: 192},
          });

But x is cutting it in the middle or near of (real y axis on displayed image)

@retyui
Copy link
Collaborator

retyui commented Aug 14, 2024

What was used to take a photo ?

@frodriguez-hu
Copy link
Author

react-native-vision-camera on the last version which with the front camera automatically mirror the photo. I mean, the photo is being well rendered

@retyui
Copy link
Collaborator

retyui commented Aug 14, 2024

well, there was a known issue with RN-vision-camera: mrousavy/react-native-vision-camera#2515 on Android


but I need to test it on my end as PR for the issue was merged: mrousavy/react-native-vision-camera#2932

@retyui
Copy link
Collaborator

retyui commented Aug 14, 2024

thx for reporting it

@frodriguez-hu
Copy link
Author

I am using the last React Native VC version

@frodriguez-hu
Copy link
Author

Do you know if there are a workaround to handle it correctly on android?

@frodriguez-hu
Copy link
Author

@retyui It worked well using takeSnapshot instead of takePhoto

@retyui
Copy link
Collaborator

retyui commented Aug 30, 2024

Do you know if there are a workaround to handle it correctly on android?

@frodriguez-hu An orientation prop from the .takePhoto() result needs to be considered.

For example:

const photo = await cameraRef.current.takePhoto({ flash: 'off' });
const isPortrait = photo.orientation.includes('portrait');
const width = isPortrait ? photo.height : photo.width;
const height = isPortrait ? photo.width : photo.height;
 ImageEditor.cropImage(`file://${photo.path}`, {
        size: {width, height},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants