react-image-crop icon indicating copy to clipboard operation
react-image-crop copied to clipboard

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

Open rajputkamal opened this issue 1 year ago • 6 comments

              ` <ReactCrop
                  crop={crop}
                  onChange={(_, percentageCrop) => setCrop(percentageCrop)}
                  onComplete={(c) =>
                    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"
                    onLoad={onImageLoad}
                    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

rajputkamal avatar Aug 07 '24 17:08 rajputkamal

did you solved it ?

Rishab-Mishra avatar Sep 12 '24 07:09 Rishab-Mishra

Yes, thanks

rajputkamal avatar Sep 12 '24 07:09 rajputkamal

@rajputkamal how?

pedrodias2703 avatar Sep 12 '24 17:09 pedrodias2703

How did you fix it?

hiimkosu1 avatar Sep 17 '24 17:09 hiimkosu1

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

rajputkamal avatar Sep 25 '24 04:09 rajputkamal

@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

digitalkrafter avatar Apr 12 '25 11:04 digitalkrafter