Image output

Speech bubble card

Social card with text in a speech bubble.

Use this example for sharing a quick quote. Replace the text and avatar image with your own to auto generate tweet like shareable images.
Preview of Speech bubble card

Interactive example

Edit and render this image

Change the HTML, CSS, or API options. The browser preview updates as you edit; select Image to render the final output through the API.

Example code

Use this request in your app

Choose a language and copy a complete request using this example's HTML, CSS, and API options.

using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Nodes;

var apiId = Environment.GetEnvironmentVariable("HCTI_API_ID")!;
var apiKey = Environment.GetEnvironmentVariable("HCTI_API_KEY")!;
using var client = new HttpClient();
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{apiId}:{apiKey}"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);

var request = new
{
    html = """
           <div class="p-4 text-center" style="width: 500px">
             <div class="speech-bubble-ds">
               This is Little Bear. He tolerates baths because he knows how phenomenal his
               floof will appear afterwards. 13/10
               <div class="speech-bubble-ds__arrow"></div>
             </div>
             <img src="https://docs.htmlcsstoimage.com/assets/images/dog.jpg" class="rounded-circle shadow mt-2" width="100px">
             <h4 class="mt-2">
               WeRateDogs
             </h4>
             <span class="text-muted">@dog_rates</span>
           </div>
           
           <!-- Include external CSS, JavaScript or Fonts! -->
           <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
           
           <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@700" rel="stylesheet">
           """,
    css = """
          
          body {
            background-color: #FFE86E !important;
          }
          
          
          .speech-bubble-ds {
            color: #FFFFFF;
            background: #000000;
            border: 1px solid #ffffff;
            border-radius: 16px;
            box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.2);
            font-size: 1.2rem;
            line-height: 1.3;
            margin: 0 auto 40px;
            max-width: 400px;
            padding: 15px;
            position: relative;
          
            p {
              margin-bottom: 10px;
          
              :last-of-type {
                margin-bottom: 0;
              }
            }
          }
          
          .speech-bubble-ds__arrow {
            border-left: 21px solid transparent;
            border-top: 20px solid rgba(0, 0, 0, 0.2);
            bottom: -25px;
            position: absolute;
            right: 200px;
          
            &::before {
              border-left: 23px solid transparent;
              border-top: 23px solid #a7a7a7;
              bottom: 2px;
              content: "";
              position: absolute;
              right: 5px;
            }
            &::after {
              border-left: 21px solid transparent;
              border-top: 21px solid #efefef;
              bottom: 4px;
              content: "";
              position: absolute;
              right: 6px;
            }
          }
          """,
    render_when_ready = false,
};

using var response = await client.PostAsJsonAsync("https://hcti.io/v1/image", request);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadFromJsonAsync<JsonObject>();
var imageUrl = result?["url"]?.GetValue<string>();
if (imageUrl is not null)
{
    Console.WriteLine(imageUrl);
}

From code to screenshot

How HCTI examples work

HTML/CSS to Image renders HTML and CSS in hosted Chrome, then captures the result as an image or PDF. Each example combines real source code with the API options used for the render, so it is both a working demo and a starting point for your own request.

Edit the source and options above to test changes in the browser, then render through the API to see the production result.

Common questions

Can I use the HTML and CSS from these examples?

Yes. Open an example to inspect and edit its complete HTML, CSS, and render options. Use it as a starting point, then send the resulting request from your application.

What is the difference between an example and a template?

Examples are complete API requests built from HTML and CSS. Templates are saved, reusable designs created in the visual editor and rendered repeatedly with different variable values.

Does HCTI create screenshots and PDFs?

Yes. HCTI can render HTML and CSS or capture a public webpage as an image, and it can generate PDFs when you need document output instead of a screenshot.

Keep exploring

Related examples

View all examples