Skip to content

Are the axis inverted when cropping? #160

@frodriguez-hu

Description

@frodriguez-hu

Ask your Question

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

Activity

retyui

retyui commented on Aug 14, 2024

@retyui
Collaborator

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

frodriguez-hu

frodriguez-hu commented on Aug 14, 2024

@frodriguez-hu
Author

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

frodriguez-hu commented on Aug 14, 2024

@frodriguez-hu
Author

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

frodriguez-hu

frodriguez-hu commented on Aug 14, 2024

@frodriguez-hu
Author

@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

retyui commented on Aug 14, 2024

@retyui
Collaborator

What was used to take a photo ?

frodriguez-hu

frodriguez-hu commented on Aug 14, 2024

@frodriguez-hu
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

retyui commented on Aug 14, 2024

@retyui
Collaborator

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

retyui commented on Aug 14, 2024

@retyui
Collaborator

thx for reporting it

frodriguez-hu

frodriguez-hu commented on Aug 14, 2024

@frodriguez-hu
Author

I am using the last React Native VC version

frodriguez-hu

frodriguez-hu commented on Aug 14, 2024

@frodriguez-hu
Author

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

frodriguez-hu

frodriguez-hu commented on Aug 14, 2024

@frodriguez-hu
Author

@retyui It worked well using takeSnapshot instead of takePhoto

retyui

retyui commented on Aug 30, 2024

@retyui
Collaborator

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @retyui@frodriguez-hu

        Issue actions

          Are the axis inverted when cropping? · Issue #160 · callstack/react-native-image-editor