Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
rajputkamal opened this issue Aug 7, 2024 · 5 comments

Comments

@rajputkamal
Copy link

              ` <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

@Rishab-Mishra
Copy link

did you solved it ?

@rajputkamal
Copy link
Author

Yes, thanks

@pedrodias2703
Copy link

@rajputkamal how?

@hiimkosu1
Copy link

How did you fix it?

@rajputkamal
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants