Link Search Menu Expand Document

Google Apps Script: HTML/CSS to Image

Generate a png, jpg or webp images with Google Apps Script.

Live demo Get an API Key


Table of contents

Generate an image with Google Apps Script

With Google Apps Script, you can build add-ons for Google. It is based on JavaScript, but includes built in functions that you’ll need to use to work with the HTML/CSS to Image API.

Our documented JavaScript examples won’t work with GAS. You can make use of the built in UrlFetchApp to generate images with the API.

Example code

This shows you how to authenticate with the API and pass parameters in a POST request. This is passing html/css parameters to the API. You can adapt this sample to pass any parameters or work with any of our endpoints.

var formData = {
  'html': 'Test',
  'css': 'test',
};

var options = {
  'method' : 'post',
  'payload' : formData
};
// Replace username with your User ID and password with your API Key
options.headers = {"Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)};
UrlFetchApp.fetch("https://hcti.io/v1/image", options);

Need help?

We’re always looking to improve this documentation. Please send us an email: support@htmlcsstoimage.com. We respond fast.


Back to top

Built with extensive integration tests and serious care for developer happiness.
© 2018-2020 Code Happy, LLC.

Page last modified: Sep 20 2020 at 06:19 PM.

Edit this page on GitHub.