gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 23:19:50 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com