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

On mobile devices, images move to the right bottom #3142

Open
Oussama-El-Benney opened this issue Feb 5, 2024 · 1 comment
Open

On mobile devices, images move to the right bottom #3142

Oussama-El-Benney opened this issue Feb 5, 2024 · 1 comment

Comments

@Oussama-El-Benney
Copy link

Oussama-El-Benney commented Feb 5, 2024

when downloading the image using desktop it works fine, but when i try on mobile devices or using the desktop responsive, downloading images started a strange behavior, as images on the downloaded canvas moves to the right bottom.
this is my code:

const captureScreenshotPlayerRecordVsTeam = async () => {
        try {
            if (divRefPlayerForm.current) {

                // Increase scale for higher quality
                const scale = 1;

                // Set DPI for higher quality
                const dpi = 300;

                const canvas = await html2canvas(divRefPlayerForm.current, {
                    scale: scale,
                    useCORS: true, // Enable CORS for capturing external images
                });

                // Convert canvas to a data URL
                const dataUrl = canvas.toDataURL('image/png', 1.0); // Use PNG format with high quality

                // You can now save or display the screenshot as needed
                console.log(dataUrl);

                // Create an anchor element for downloading
                const downloadLink = document.createElement('a');
                downloadLink.href = dataUrl;
                downloadLink.download = `${selectedElement?.web_name} form ${ (home && !away) ? " Home " : (away && !home) ? " Away " : '' } GW${startGw}-${endGw}.png`; // Specify the filename

                // Trigger the download programmatically
                downloadLink.click();

            }
        } catch (error) {
            console.error('Error capturing screenshot:', error);
        } finally {
        }
    };

I searched and found this solution but its not working.

// Adjust viewport for mobile devices
                if (screen.width < 1024) {
                    document.getElementById("viewport")?.setAttribute("content", "width=1200px");
                }

fixture-difficulty-rating Saka GW24

@SwayamFlipr
Copy link

I am facing a similar issue but the in my case image gets shifted to top left and also get cropped automatically, basically mobile device is unable to capture the whole image in the canvas

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

2 participants