ecmadao / coding-guide Goto Github PK
View Code? Open in Web Editor NEW自己随手记录的东西
License: Apache License 2.0
自己随手记录的东西
License: Apache License 2.0
经过调研,我目前发现的方法如下(使用 Node ):
利用 phantom.js 的 render
phantomjs-node,对 phantom.js 进行了一层封装
这是我尝试的目前效果最好的方法,可以直接自行封装一个脚本,由前端调用 API 后触发。但渲染速度不尽人意,不过也应该有一些优化的空间。
// demo
const phantom = require('phantom');
(async function() {
const instance = await phantom.create();
const page = await instance.createPage();
await page.property('viewportSize', {width: 1024, height: 600});
const status = await page.open('https://stackoverflow.com/');
console.log(`Page opened with status [${status}].`);
await page.render('stackoverflow.pdf');
console.log(`File created at [./stackoverflow.pdf]`);
await instance.exit();
}());
生成网页截屏。但只能是 png、jpg、jpeg 形式,且无法滚屏截图,只能指定图片高度或者按照窗口大小截取(目前没有找到合适的方式)
// demo
var webshot = require('webshot');
webshot('google.com', 'google.png', function(err) {
// screenshot now saved to google.png
});
暂时还没有尝试,看见在 stackoverflow 上有人推荐,也有人反馈说该库有很奇怪的 bug
相对于上面的方法,该库是在前端调用,将一个指定的 DOM 转为 base64 格式的图片,并可以保留其样式。但缺点很明显,由于是前端使用,在 DOM 数目较多时会有明显的卡顿,体验不好。
// demo
domtoimage.toJpeg(document.getElementById('my-node'))
.then(function (dataUrl) {
var link = document.createElement('a');
link.download = 'my-image-name.jpeg';
link.href = dataUrl;
link.click();
});
stackoverflow 上的讨论 - HTML to PDF with Node.js
使用RxJS处理4G文件的读取加密写入时,尽管不需要申请一块连续的4G内存,但仍然需要申请许多的64k内存块,这样仍会对GC造成比较大的压力。个人认为使用NodeJs中的stream.pipe来实现这个场景更为合适,不知道我的理解是否正确?
下面这段代码为什么没有产生一个vendor.bundle.js在output.path路径下,但是去掉children又是可以产生的
new webpack.optimize.CommonsChunkPlugin({ filename:'vendor.bundle.js', name: 'vendor', // Move dependencies to our main file children: true, // Look for common dependencies in all children, minChunks: 2, // How many times a dependency must come up before being extracted })
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.