Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

HTML/CSS to Image - Ruby

Test Gem Version

Ruby client for the HTML/CSS to Image API.

Generate png, jpg or webp images with Ruby. Renders exactly like Google Chrome.


Add this line to your application's Gemfile:

gem 'htmlcsstoimage-api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install htmlcsstoimage-api


Create a new instance of the API client.

# Retrieve your user id and api key from
client = "user-id", api_key: "api-key")

Using Environment variables

Alternatively, you can set ENV["HCTI_USER_ID"] and ENV["HCTI_API_KEY"]. These will be loaded automatically.

client =

Create an image

Generate an image from HTML/CSS. Returns a URL to the image.

image = client.create_image("<div>Hello, world</div>",
                            css: "div { background-color: red; font-family: Roboto; }",
                            google_fonts: "Roboto")

=> #<HTMLCSSToImage::ApiResponse url="", id="254b444c-dd82-4cc1-94ef-aa4b3a6870a6">
=> ""

Delete an image

Delete an existing image. Removes the image from HCTI servers and clears the CDN.


URL to image

Generate a screenshot of any public URL.

image = client.url_to_image("", viewport_width: 800, viewport_height: 1200)


A template allows you to define HTML that includes variables to be substituted at the time of image creation. Learn more about templates.

template = client.create_template("<div>{{title}}</div>")
# => #<HTMLCSSToImage::ApiResponse template_id="t-56c64be5-5861-4148-acec-aaaca452027f", template_version=1596829374001>

# Get templates
all_templates = client.templates

# Create a signed URL for a templated image
image = client.create_image_from_template(template.template_id, { title: "Hello, world!" })
# => #<HTMLCSSToImage::ApiResponse url="">

# => ""

Additional methods

See the ruby-client docs for all of the available methods.

Available parameters

For detailed information on all the available parameters, visit the docs:


After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to

To generate the Yard docs, run yard doc -o docs and commit the changes.


For help with the API, you can also contact


Bug reports and pull requests are welcome on GitHub at


The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.