node-html-to-image icon indicating copy to clipboard operation
node-html-to-image copied to clipboard

Blurry image

Open AlessandroAries opened this issue 4 years ago β€’ 6 comments

When I just try a simple example like this:

nodeHtmlToImage({
        html: `<html><body>Hello world!</body></html>`,
        type: "png",
        output: "./image.png",
    });

I get a blurry image as output, any idea how this is possible? image

AlessandroAries avatar Feb 09 '21 13:02 AlessandroAries

Hi @AlessandroAries πŸ‘‹

Thank you for opening this issue πŸ™ You can try to change the quality in the options to improve it. Tell me if it is better after this πŸ˜„

frinyvonnick avatar Feb 09 '21 14:02 frinyvonnick

Hi @AlessandroAries πŸ‘‹

Thank you for opening this issue πŸ™ You can try to change the quality in the options to improve it. Tell me if it is better after this πŸ˜„

Hi, I already tried that with jpeg, but didn't work and for png it also doesn't work (also because thats not used occording to the documentation)

AlessandroAries avatar Feb 09 '21 18:02 AlessandroAries

is there any solution? i have the same problem

YonatanHanan avatar Jul 01 '21 20:07 YonatanHanan

You could try to set the deviceScaleFactor. You can pass options to puppeteer using puppeteerArgs property. Let me know if it works.

frinyvonnick avatar Jul 02 '21 07:07 frinyvonnick

@AlessandroAries or @YonatanHanan did you try to set the deviceScaleFactor?

frinyvonnick avatar Feb 12 '22 20:02 frinyvonnick

Hi, I have the same issue. Can you please show me how to pass that option? will this work? puppeteerArgs: {'defaultViewport.deviceScaleFactor' : '1'},

image

This is how I see the created image

amihos avatar Jul 20 '22 10:07 amihos

Hi, i tried using defaultViewport.deviceScaleFactor, but it seems doesn't works, then i tried with

puppeteerArgs: {
                'defaultViewport': {
                    'deviceScaleFactor': 2
                }
            }

it give me an error UnhandledPromiseRejectionWarning: Error: Unable to get browser page,

it will works if i using beforeScreenshot parameter, but then it needs specific width and height value

any suggestion ?

myoganugraha avatar Jul 27 '23 14:07 myoganugraha

Same as @myoganugraha.

igor9silva avatar Jul 31 '23 23:07 igor9silva

hi @igor9silva, my solution is using beforeScreenshot argument, to handle dynamic height of my document, i'm using

const height = await page.evaluate(
          () => document.documentElement.offsetHeight
);

inside my beforeScreenshot, and here's full example

beforeScreenshot: async (page: any) => {
        const height = await page.evaluate(
          () => document.documentElement.offsetHeight
        );
        await page.setViewport({
          width: 375,
          height: height,
          deviceScaleFactor: 1.6
        });
      },

myoganugraha avatar Aug 01 '23 08:08 myoganugraha

hi @igor9silva, my solution is using beforeScreenshot argument, to handle dynamic height of my document, i'm using


const height = await page.evaluate(

          () => document.documentElement.offsetHeight

);

inside my beforeScreenshot, and here's full example


beforeScreenshot: async (page: any) => {

        const height = await page.evaluate(

          () => document.documentElement.offsetHeight

        );

        await page.setViewport({

          width: 375,

          height: height,

          deviceScaleFactor: 1.6

        });

      },

Oh, very interesting, thanks for sharing!

igor9silva avatar Aug 01 '23 11:08 igor9silva

Thank you @myoganugraha for providing the solution πŸ‘ I close this issue since it seems to fix it πŸ˜„

frinyvonnick avatar Aug 05 '23 11:08 frinyvonnick

@myoganugraha’s solution also worked for me, thanks!

igor9silva avatar Aug 05 '23 12:08 igor9silva