- Take the screenshot
- Upload it to an S3 bucket
npm install s3
npm install webshot
node screen.js http://url/to/my/page
Created by Makis Tracend ( @tracend )
| node_modules |
| // configure | |
| module.exports = { | |
| aws: { | |
| key: "0000_S3_KEY_0000", | |
| secret: "0000_S3_SECRET_0000", | |
| bucket: "S3_BUCKET" | |
| }, | |
| screenSize: { width: 1024, height: 768 }, | |
| delay: 5000, | |
| path: '/', // this is the path in the S3 bucket where the image will be saved | |
| filename: false | |
| } |
| { | |
| "name": "thumbnail-app", | |
| "version": "0.1.0", | |
| "author": "tracend", | |
| "contributors": [ | |
| { | |
| "name": "Makis Tracend", | |
| "email": "[email protected]" | |
| } | |
| ], | |
| "homepage": "http://makesites.org", | |
| "repository": { | |
| "type": "git", | |
| "url": "git://gist.github.com/tracend/5735129.git" | |
| }, | |
| "bugs": { | |
| "url": "https://gist.github.com/tracend/5735129" | |
| }, | |
| "licenses": [ | |
| { | |
| "type": "MIT", | |
| "url": "http://makesites.org/licenses/MIT" | |
| } | |
| ], | |
| "engines": { | |
| "node": ">=0.8.x" | |
| }, | |
| "main": "screen", | |
| "scripts": { | |
| "start": "screen.js" | |
| }, | |
| "dependencies": { | |
| "s3" : "*", | |
| "webshot" : "*" | |
| } | |
| } |
| // dependencies | |
| var fs = require('fs'), | |
| s3 = require('s3'), | |
| webshot = require('webshot'), | |
| config = require('./config'); | |
| // createClient allows any options that knox does. | |
| var client = s3.createClient( config.aws ); | |
| // pass the URL as a command line argument | |
| var url = process.argv[2]; | |
| var file = ( config.filename ) ? config.filename : url.substring(url.lastIndexOf('/')+1)+'.png'; | |
| var options = { | |
| renderDelay: config.delay || 0, | |
| windowSize: config.screenSize, | |
| shotSize : { width: 'window', height: 'window' } | |
| } | |
| webshot( url, file, options, function(err) { | |
| // error check? | |
| // upload a file to s3 | |
| var uploader = client.upload(file, config.path+file); | |
| uploader.on('error', function(err) { | |
| console.error("unable to upload:", err.stack); | |
| }); | |
| uploader.on('end', function(url) { | |
| // delete local file | |
| fs.unlink( file ); | |
| console.log("file available at", url); | |
| }); | |
| }); |