Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (24 sloc) 1.01 KB
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.

{% code-tabs %} {% code-tabs-item title="image.rb" %}

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"=>""}

{% endcode-tabs-item %} {% endcode-tabs %}

More examples

For more advanced examples, take a look here.