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

Why is the text blurred after being translated into pictures? #571

Closed
lidongzhangg opened this issue Aug 28, 2017 · 5 comments
Closed

Why is the text blurred after being translated into pictures? #571

lidongzhangg opened this issue Aug 28, 2017 · 5 comments

Comments

@lidongzhangg
Copy link

lidongzhangg commented Aug 28, 2017

Why is the text blurred after being translated into pictures?

code like this:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('http://www.baidu.com');
  await page.screenshot({path: '/Users/ldz/Downloads/xx.jpg'});

  browser.close();
})();
@ebidel
Copy link
Contributor

ebidel commented Aug 28, 2017

Are you on a retina machine? If so, you may need to set the deviceScaleFactor to match the DPR of the device.

Something like:

const page = await browser.newPage();
await page.setViewport({width: 800, height: 800, deviceScaleFactor: 2});

By default, puppeteer uses deviceScaleFactor: 1

@lidongzhangg
Copy link
Author

Yes, it is the retina screen, the problem is solved, thanks!

@LastTribunal
Copy link

I have a problem with this feature. When you increase the deviceScaleFactor, you also increase the aspect, so the image although becomes sharper, it also becomes bigger. How do you increase quality without scaling up the image?
Note, this is not an issue in PDFs, obviously, since the fonts are vectorized

@csandman
Copy link

csandman commented Dec 17, 2020

I have a problem with this feature. When you increase the deviceScaleFactor, you also increase the aspect, so the image although becomes sharper, it also becomes bigger. How do you increase quality without scaling up the image?
Note, this is not an issue in PDFs, obviously, since the fonts are vectorized

This comment was a while ago, but as a lot of people seem to agree with it I wanted to address it. This is just not how images work. If the pixel density of an image doesn't match the device you're viewing it on, it will look blurry. There is no way around this unless you shrink the image to look smaller on your screen to match your pixel density. What you're asking for is impossible.

It's basically the same thing as asking for a 1080p video to look like a 4k video on a 4k TV without changing the resolution of the video.

That is unless you're just talking about how it appears when you open it on your computer, in which case you could fix this by changing the DPI metadata on the image file. This changes nothing about the data in the image, just how certain devices decide to open them. This can be done with different packages for node or in the browser.

@matmilbury
Copy link

@csandman is correct, dpi should be bumped. This is what worked for me:

sharp(screenshot).withMetadata({ density: 144 }).toBuffer()

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

6 participants