# 实列利用puppeteer转成图片
网页宽度:
px
nodejs端代码如下
const Base = require("../base.js");
const txyoss = require("../public/txyoss");
const puppeteer = require("puppeteer");
// 网页整屏截图
module.exports = class extends Base {
async indexAction() {
const width = parseInt(this.get("pageWidth")) || 1920;
const browser = await puppeteer.launch({
defaultViewport: {
width: width,
height: 937,
},
});
const fileName = "example.png";
const page = await browser.newPage();
await page.goto(this.get("url"));
const jnnse = await page.screenshot({ path: fileName, fullPage: true });
let imgurl = await txyoss.upbuff(jnnse, "ysjpg", ".png");
await browser.close();
this.success(imgurl);
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24