javascript - 如何通过 PhantomJs 获取高质量的 html 快照图像?

标签 javascript node.js phantomjs

我正在使用 PhantomJs 截取 HTML 页面的屏幕截图。我已经将质量参数设置为 100,但图像质量仍然太低。有什么方法可以提高图像质量吗?还是有其他更好的工具可以完成这项工作?

最佳答案

您可以更改视口(viewport)大小,即分辨率,例如:

const phantom = require('phantom');   
const address = "https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Hubble2005-01-barred-spiral-galaxy-NGC1300.jpg/1920px-Hubble2005-01-barred-spiral-galaxy-NGC1300.jpg";

phantom.create().then( (ph) => {
  ph.createPage().then( (page) => {
    page.open(address).then( (status) =>  {
      console.log('Opened page: ' + address + ' Status: ' + status);
      page.property('viewportSize', { width: 1920, height: 1096} )
      page.render('test.jpg', {format: 'jpeg', quality: '100'}).then(() => {;
        console.log('Rendered page.');
        ph.exit();
      });
    });
  });
});

这将为您提供更好的图像质量。默认大小相对较低。

关于javascript - 如何通过 PhantomJs 获取高质量的 html 快照图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51136824/

相关文章:

javascript - 从没有父键的其他对象数组中的对象中删除父键

performance - 从 Node.js 释放所需的模块

javascript - 我怎样才能把这一系列的javascript变量变成一个函数呢?

html - Sendgrid 始终发送文本电子邮件

node.js - 如何在phantomjs中设置代理

javascript - 在 Azure Web 作业中使用 PhantomJS 获取网站 html 源

javascript - 如何仅在必要时在 JavaScript 中舍入数字

javascript - 如何制作可以悬停的画廊或视频或图像缩略图并显示更大的图像?

javascript - 如何在同一列Javascript中对数字和文本进行排序

javascript - 如何使用 PhantomJS (1.9.8) 将点击事件发送到 div 或按钮?