8000 Not able to catch exact crop image · Issue #566 · dominictobias/react-image-crop · GitHub
[go: up one dir, main page]

Skip to content

Not able to catch exact crop image #566

Open

Description

@iamkashhif

when I am getting the Final Crop image, not equal matching my crop area image, let me know, if i am doing wrong

also its not working in macBook.

image

const handleCropComplete = (crop: any) => {
    setCompletedCrop(crop);
    if (crop.width && crop.height) {
      // Generate the cropped image data URL
      const image = new Image();
      image.src = ProfileImage;
      const canvas = document.createElement("canvas");
      canvas.width = crop.width;
      canvas.height = crop.height;
      const ctx = canvas.getContext("2d");

      if (ctx) {
        ctx.drawImage(
          image,
          crop.x,
          crop.y,
          crop.width,
          crop.height,
          0,
          0,
          crop.width,
          crop.height
        );

        const croppedDataURL: any = canvas.toDataURL("image/jpeg");
        setCroppedImage(croppedDataURL);
      }
    }
  };

Activity

  1. MrSala commented on Feb 20, 2024

    @MrSala

    I'm having exactly the same issue after bumping up from v8 to v11 (when img src got introduced as a children).

    Did some digging by resizing my image to the same image as my modal for cropping and it worked almost fine.

    So it seems to me it's cropping the original image while not taking into the factor scaled down coordinates, like maybe part of the code is not being fired at all?

    Wild guess though.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0