Created
February 21, 2020 01:05
-
-
Save manojhl/7554bf10e3dc325570fc3a2dcfb14578 to your computer and use it in GitHub Desktop.
Image generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require("http"); | |
const puppeteer = require("puppeteer"); | |
var express = require("express"); | |
var app = express(); | |
const hostname = "localhost"; | |
const port = 3000; | |
const server = app.get("/", function(req, res) { | |
const url = req.query.url; | |
const name = req.query.name; | |
const path = "imgs/" + name; | |
console.log(); | |
console.log(new Date().toUTCString()); | |
console.log(url); | |
console.log("http://157.230.44.162/" + path); | |
(async () => { | |
const browser = await puppeteer.launch({ | |
ignoreDefaultArgs: ["--disable-extensions"], | |
args: ["--no-sandbox", "--disable-setuid-sandbox"] | |
}); | |
const page = await browser.newPage(); | |
await page.goto(url); | |
await page.screenshot({ | |
path: path, | |
clip: { x: 0, y: 0, width: 1200, height: 600 } | |
}); | |
await browser.close(); | |
})(); | |
res.send({ url: "http://157.230.44.162/" + path }); | |
}); | |
server.listen(port, hostname, () => { | |
console.log(`Server running at http://${hostname}:${port}/`); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "image-generator", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"dependencies": { | |
"express": "^4.17.1", | |
"puppeteer": "^1.17.0" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "git+https://github.com/wwf-sg/image-generator.git" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"bugs": { | |
"url": "https://github.com/wwf-sg/image-generator/issues" | |
}, | |
"homepage": "https://github.com/wwf-sg/image-generator#readme" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment