Image output

Quote with highlighted text

Share an article with highlighted text.

This example was inspired by Medium's original text shot images they shared on Twitter. It shows part of an article with a specific part highlighted.
Preview of Quote with highlighted text

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.

require "json"
require "net/http"
require "uri"

request = {
    html: <<~'HCTI_HTML',
          <div class="card m-2" style="width: 500px;">
            <div class="card-body">
          <div class="d-inline-flex">
              <div class="mr-2">
                <img src="https://miro.medium.com/fit/c/240/240/1*DOP75bHPy-SvmqMYsf3q8g.jpeg" class="rounded mx-auto d-block" alt="..." width="60px">
              </div>
              <div>
                <h5 class="card-title">Markham Heid</h5>
                <h6 class="card-subtitle mb-2 text-muted">@mheidj</h6>
              </div>
              </div>
              <p class="card-text">These pro-carb, anti-fat nutrition guidelines remained in place for decades, while rates of obesity and its attendant diseases skyrocketed among Americans. <span class="highlight">Many experts now say that the advice to avoid fat in favor of carbs was never supported by hard science</span>, and that healthy sources of fat are an essential component of a proper diet.</p>
            </div>
            <div class="card-footer text-muted">
              from "Why Food Experts Can’t Agree on Coconut Oil"
            </div>
          </div>
          <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
          HCTI_HTML
    css: <<~'HCTI_CSS',
         .highlight {
           background-color: #D3F4FF;
           padding: 3px;
           font-style: oblique;
           font-weight: 600;
         }
         body {
           background-color: #03B875 !important;
         }
         .card {
           border: #212529 4px solid !important;
         }
         HCTI_CSS
}

uri = URI("https://hcti.io/v1/image")
http_request = Net::HTTP::Post.new(uri)
http_request.basic_auth(ENV.fetch("HCTI_API_ID"), ENV.fetch("HCTI_API_KEY"))
http_request["Content-Type"] = "application/json"
http_request.body = JSON.generate(request)

response = Net::HTTP.start(
    uri.hostname,
    uri.port,
    use_ssl: true,
    open_timeout: 10,
    read_timeout: 30
) { |http| http.request(http_request) }

unless response.is_a?(Net::HTTPSuccess)
    raise format("HCTI request failed (%s): %s", response.code, response.body)
end

result = JSON.parse(response.body)
puts result.fetch("url")

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