8000 While trying to rotate the image, the image itself is not fitting inside the container, full image is not visible after rotating to 90 or 270 degree · Issue #598 · dominictobias/react-image-crop · GitHub
[go: up one dir, main page]

Skip to content

While trying to rotate the image, the image itself is not fitting inside the container, full image is not visible after rotating to 90 or 270 degree #598

Open

Description

@rajputkamal
              ` <ReactCrop
                  crop={crop}
                   percentageCrop) => setCrop(percentageCrop)}
                   =>
                    setCompletedCrop && setCompletedCrop(c)
                  }
                  aspect={builderLandscapeAspectRatio(builderAspectRatio)} // passing different aspect ratios
                  keepSelection
                  style={{
                    minHeight: "100%",
                    height: "auto",
                  }}
                >
                  <StyledImage
                    id="cropped-image"
                    ref={imgRef}
                    src={largeThumbnailMediaurl}
                    alt="Crop me"
                    
                    style={{
                      transform: `scale(${scale}) rotate(${rotate}deg)`,
                    }}
                  />
             </ReactCrop>`

I tried the below approach to swap the height and width during the rotation.

                `const image = document.getElementById("cropped-image") as HTMLCanvasElement;
                  const reactCropperContainer = document.querySelector(
                    ".ReactCrop--fixed-aspect",
                  ) as HTMLDivElement;
                  
                  const isRotated = [90, 270, -90, -270].includes(degree);
                  
                  if (isRotated) {
                      reactCropperContainer.style.width = `${newHeight}px`;
                      reactCropperContainer.style.height = `${newWidth}px`;
                      image.style.transform = `scale(${scale}) rotate(${rotate}deg)`;
                    } else {
                      reactCropperContainer.style.width = `${newWidth}px`;
                      reactCropperContainer.style.height = "100%";
                      image.style.transform = `scale(${scale}) rotate(${rotate}deg)`;
                  }`

but this approach is also not working. My main problem is image is entirely not fitting inside the container during rotation

Activity

  1. Rishab-Mishra commented on Sep 12, 2024

    @Rishab-Mishra

    did you solved it ?

  2. rajputkamal commented on Sep 12, 2024

    @rajputkamal
    Author

    Yes, thanks

  3. pedrodias2703 commented on Sep 12, 2024

    @pedrodias2703
  4. hiimkosu1 commented on Sep 17, 2024

    @hiimkosu1

    How did you fix it?

  5. rajputkamal commented on Sep 25, 2024

    @rajputkamal
    Author

    I fixed by making internal API calls to return the updated image url with rotation.

  6. digitalkrafter commented on Apr 12, 2025

    @digitalkrafter

    @rajputkamal i am also getting same issue while image in vertical position not able to crop the image

    could you please provide the solution what you have

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