Converting HTML/CSS to an Image with Ruby

This example uses the HTTParty gem. Install with gem install httparty, or add it to your Gemfile.

Example code

This code sample sets your authorization header and does a POST with HTML/CSS to the API. The response will be json with the URL to the generated image.

require "httparty"
# Retrieve your user id and api key from the Dashboard
auth = { username: 'user_id', password: 'api_key' }
html = "<div class='ping'>Pong ✅</div>"
css = ".ping { padding: 20px; font-family: 'sans-serif'; }"
image ="",
body: { html: html, css: css },
basic_auth: auth)
# => {"url"=>""}

More examples

For more advanced examples, take a look here.