Skip to content

Instantly share code, notes, and snippets.

@parsibox
Last active December 25, 2017 07:11
Show Gist options
  • Save parsibox/5d690b4239e848afa253b529fab1a7a2 to your computer and use it in GitHub Desktop.
Save parsibox/5d690b4239e848afa253b529fab1a7a2 to your computer and use it in GitHub Desktop.
node js take screenshot whole page size
'use strict'
const express = require('express')
const bodyParser = require('body-parser')
var webshot = require('/root/node-webshot/lib/webshot')
var options = { shotSize: { height: 'all' } , renderDelay : 500 , quality : 75 };
const app = express()
app.use(bodyParser.urlencoded({ extended: false }))
app.use('/images', express.static(__dirname + '/images'))
app.post('/web', function (req, res) {
const myurl = req.body.myurl ;
const mytitle = req.body.mytitle;
webshot( myurl, '/root/node-webshot/webscreen/images/'+mytitle+'.png' , options, function(err) {
if( err){
console.log(`error: ${err}`);
}
});
res.set('Content-Type', 'text/plain');
res.send(`You sent: ${myurl} to Express`);
})
app.listen(8080, function (err) {
if (err) {
throw err
}
console.log('Server started on port 8080')
})
@parsibox
Copy link
Author

node webscreen.js
curl --data "myurl=mohsendavari.ir&mytitle=mohsen" localhost:8080/web
localhost:8080/images/mohsen.png

@parsibox
Copy link
Author

first install https://github.com/brenden/node-webshot
thene install npm install express body-parser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment