commit 706651c178043c185c44af3ffa73296f7c59d62c Author: Knut Ahlers Date: Thu Jul 28 23:28:19 2016 +0200 initial version diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..16c7987 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM nolimitid/node-phantom + +RUN set -ex \ + && apt-get update \ + && apt-get install -y imagemagick + +VOLUME ["/data"] +ENTRYPOINT ["/usr/local/bin/run.sh"] +CMD [] + +ADD index.js /src/index.js +ADD run.sh /usr/local/bin/run.sh diff --git a/index.js b/index.js new file mode 100644 index 0000000..20e70a5 --- /dev/null +++ b/index.js @@ -0,0 +1,37 @@ +var page = require('webpage').create(), + system = require('system'); + +browser_width = 2560 +browser_height = browser_width / 297 * 210 + +page.viewportSize = { width: browser_width, height: browser_height }; +page.settings.webSecurityEnabled = false +page.settings.resourceTimeout = 5000 +page.settings.localToRemoteUrlAccessEnabled = true + +if (system.args.length !== 4) { + console.log('Usage: '+system.args[0]+' '); + phantom.exit(); +} + +var url = [ + 'http://openfiremap.org/', + '?zoom=', system.args[1], + '&lat=', system.args[2], + '&lon=', system.args[3], + '&layers=B0000TF', +].join(''); + +console.log("Fetching URL " + url); + +page.open(url, function(status) { + if (status !== 'success') { + console.log('Unable to load the address!'); + phantom.exit(); + } else { + window.setTimeout(function () { + page.render('/data/shot.png'); + phantom.exit(); + }, 5000); // Change timeout as required to allow sufficient time + } +}); diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..9700565 --- /dev/null +++ b/run.sh @@ -0,0 +1,18 @@ +#!/bin/bash -ex + +DPI=150 +W=1754 # 150 x 11.69 +H=1241 # 150 x 8.27 + +/usr/bin/phantomjs /src/index.js "$@" + +TARGET="map_$(date +%Y-%m-%d_%H-%M)" +mv /data/shot.png /data/${TARGET}.png + +#exec convert /data/${TARGET}.png -compress jpeg -quality 90 \ +# -resize ${W}x${H} -density ${DPI} \ +# -repage ${W}x${H} /data/${TARGET}.pdf +exec convert /data/${TARGET}.png -compress jpeg -quality 90 \ + -resize ${W}x${H} -gravity center -extent ${W}x${H} \ + -units PixelsPerInch -set density ${DPI} \ + -repage ${W}x${H} /data/${TARGET}.pdf