How to convert HTML to a base64 image with Puppeteer and Ruby

The most popular way to do it is with the Grover gem. Grover is a wrapper around Puppeteer that makes it easy to generate images from HTML.

Install Puppeteer and Grover

npm i puppeteer
gem install grover

Get the base64 encoded image of some HTML

require 'grover'
require 'base64'

@image = Base64.strict_encode64(Grover.new('<h1>Hello World</h1>').to_png)

image

We created Urlbox to make converting HTML to images easy

Learn more about our website screenshot API.