Files
drawlogo/scripts/test-transparent.js
T

31 lines
1.5 KiB
JavaScript

'use strict';
const fs = require('fs');
const path = require('path');
const { spawn } = require('child_process');
const ROOT = path.resolve(__dirname, '..');
const CHROME = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe';
const SIZE = 512;
const svg = fs.readFileSync(path.join(ROOT, 'output', 'agent-avatars-png', 'avatars', 'bottts', 'bottts-001.svg'), 'utf8');
const html = `<!DOCTYPE html><html><head><meta charset="utf-8">
<style>html,body{margin:0;padding:0;width:${SIZE}px;height:${SIZE}px;overflow:hidden;background:transparent}
.wrap{width:${SIZE}px;height:${SIZE}px;display:flex;align-items:center;justify-content:center}</style>
</head><body><div class="wrap">${svg.replace('<svg ', '<svg width="' + SIZE + '" height="' + SIZE + '" ')}</div></body></html>`;
const hf = path.join(ROOT, 'output', '.tmp-test2.html');
fs.writeFileSync(hf, html, 'utf8');
const out = path.join(ROOT, 'output', 'test-t2.png');
const p = spawn(CHROME, [
'--headless=new', '--disable-gpu', '--hide-scrollbars',
'--default-background-color=00000000',
'--force-device-scale-factor=1',
'--window-size=' + SIZE + ',' + SIZE, '--virtual-time-budget=1000',
'--screenshot=' + out,
'file:///' + hf.replace(/\\/g, '/')
]);
p.stdout.on('data', d => process.stdout.write('[out] ' + d));
p.stderr.on('data', d => process.stdout.write('[err] ' + d));
p.on('close', code => {
console.log('exit code:', code);
console.log('png exists:', fs.existsSync(out), fs.existsSync(out) ? fs.statSync(out).size : 0);
});