Giter Site home page Giter Site logo

phantomjs-html-to-png-on-heroku's Introduction

phantomjs-html-to-png-on-heroku

Run PhantomJS powered rendering server on Heroku, which produces PNG out of HTML.

This project is heavily inspired by: https://github.com/vgno/highcharts-png-renderer

Run locally

git clone [email protected]:jussikinnula/phantomjs-html-to-png-on-heroku.git
brew install phantomjs
npm install
npm start

Make API calls

curl -X POST -d '{ "html": "<html><body><h1>Hello World!</h1></body></html>", "width": 640, "height": 480, "format": "png",  "onload": false, "timeout": 50 }' http://localhost:5000

Parameters

  • html = input HTML to convert into image
  • width = width of the PhantomJS headless browser (e.g. translates to width of rendered image)
  • height = height of the PhantomJS headless browser (e.g. translates to height of rendered image)
  • format = supported formats are: png and jpg (gif could possibly be used if running the backend on supported systems)
  • onload = boolean true or false -- use PhantomJS capacity to detect when the page has been rendered (this doesn't work with HTML pages with SVG)
  • timeout = if onload is false, use this timeout instead to determine when to take the screenshot from HTML (50ms works for most of the cases, you can tune it down based on the type of HTML used)

Deploy to Heroku

heroku create --region eu
heroku buildpacks:add https://github.com/stomita/heroku-buildpack-phantomjs
heroku buildpacks:add https://github.com/heroku/heroku-buildpack-nodejs
git push heroku master

Fonts

You should include all the fonts needed under .fonts directory, instead of loading web fonts. PhantomJS is not always fast enough to load web fonts. The fonts should be in TrueType format.

phantomjs-html-to-png-on-heroku's People

Contributors

jussikinnula avatar

Watchers

 avatar

Forkers

tomblyatka

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.