|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
const log4js = require("log4js");
|
|
|
const webshot = require("webshot");
|
|
|
const read = require("read-all-stream");
|
|
|
+const pngjs_1 = require("pngjs");
|
|
|
const logger = log4js.getLogger('webshot');
|
|
|
logger.level = 'info';
|
|
|
function renderWebshot(url, height) {
|
|
@@ -17,16 +18,36 @@ function renderWebshot(url, height) {
|
|
|
quality: 100,
|
|
|
customCSS: 'html{zoom:2}header{display:none!important}',
|
|
|
};
|
|
|
- const renderStream = webshot(url, options);
|
|
|
- read(renderStream, 'base64').then(data => {
|
|
|
- resolve(data);
|
|
|
+ webshot(url, options).pipe(new pngjs_1.PNG({
|
|
|
+ filterType: 4
|
|
|
+ }))
|
|
|
+ .on('parsed', function () {
|
|
|
+ let boundary = null;
|
|
|
+ for (let y = 0; y < this.height; y++) {
|
|
|
+ const x = 0;
|
|
|
+ let idx = (this.width * y + x) << 2;
|
|
|
+ if (this.data[idx] !== 255) {
|
|
|
+ boundary = y;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (boundary != null) {
|
|
|
+ this.data = this.data.slice(0, (this.width * boundary) << 2);
|
|
|
+ this.height = boundary;
|
|
|
+ read(this.pack(), 'base64').then(data => {
|
|
|
+ resolve({ data, boundary });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ resolve({ data: '', boundary });
|
|
|
+ }
|
|
|
});
|
|
|
});
|
|
|
return promise.then(data => {
|
|
|
- if (height < 2048)
|
|
|
+ if (data.boundary != null)
|
|
|
return renderWebshot(url, height * 2);
|
|
|
else
|
|
|
- return data;
|
|
|
+ return data.data;
|
|
|
});
|
|
|
}
|
|
|
/*function fetchImage(): Promise<string> {
|