Skip to content

Not able to catch exact crop image #566

@iamkashhif

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);
      }
    }
  };

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