Image output

QR Code Badge

Simple, artistic badge with a QR code.

You can generate thousands of images easily, with different text and QR codes.

To change the value of the QR code, edit the data parameter in the HTML.

Preview of QR Code Badge

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.

<?php

$request = [
    "html" => <<<'HCTI_HTML'
        <div class="wrapper text-center d-block p-4">
          <h1 class="text-white p-4 m-4">Debra <span class="highlight">Fraser</span></h1>
          <img src="https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https://htmlcsstoimage.com" class="mb-4"/>
        </div>
        
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
        
        
        HCTI_HTML,
    "css" => <<<'HCTI_CSS'
        html,body {
        font-family: Inter;
        }
        .wrapper {
          width: 800px;
          background-color: #ff9d00;
          background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25' viewBox='0 0 1600 800'%3E%3Cg stroke='%23000' stroke-width='66.7' stroke-opacity='0.05' %3E%3Ccircle fill='%23ff9d00' cx='0' cy='0' r='1800'/%3E%3Ccircle fill='%23fb8d17' cx='0' cy='0' r='1700'/%3E%3Ccircle fill='%23f47d24' cx='0' cy='0' r='1600'/%3E%3Ccircle fill='%23ed6e2d' cx='0' cy='0' r='1500'/%3E%3Ccircle fill='%23e35f34' cx='0' cy='0' r='1400'/%3E%3Ccircle fill='%23d85239' cx='0' cy='0' r='1300'/%3E%3Ccircle fill='%23cc453e' cx='0' cy='0' r='1200'/%3E%3Ccircle fill='%23be3941' cx='0' cy='0' r='1100'/%3E%3Ccircle fill='%23b02f43' cx='0' cy='0' r='1000'/%3E%3Ccircle fill='%23a02644' cx='0' cy='0' r='900'/%3E%3Ccircle fill='%23901e44' cx='0' cy='0' r='800'/%3E%3Ccircle fill='%23801843' cx='0' cy='0' r='700'/%3E%3Ccircle fill='%236f1341' cx='0' cy='0' r='600'/%3E%3Ccircle fill='%235e0f3d' cx='0' cy='0' r='500'/%3E%3Ccircle fill='%234e0c38' cx='0' cy='0' r='400'/%3E%3Ccircle fill='%233e0933' cx='0' cy='0' r='300'/%3E%3Ccircle fill='%232e062c' cx='0' cy='0' r='200'/%3E%3Ccircle fill='%23210024' cx='0' cy='0' r='100'/%3E%3C/g%3E%3C/svg%3E");
          background-attachment: fixed;
          background-size: cover;
        }
        h1 {
          font-size: 4rem !important;
          text-shadow: 10px 10px 20px rgba(0, 0, 0, 0.5);
        
        }
        img {
          box-shadow: 10px 10px 20px rgba(0, 0, 0, 0.5);
        }
        
        HCTI_CSS,
    "google_fonts" => "Inter",
];

$curl = curl_init("https://hcti.io/v1/image");
curl_setopt_array($curl, [
    CURLOPT_POST => true,
    CURLOPT_USERPWD => sprintf("%s:%s", getenv("HCTI_API_ID"), getenv("HCTI_API_KEY")),
    CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
    CURLOPT_POSTFIELDS => json_encode($request, JSON_THROW_ON_ERROR),
    CURLOPT_RETURNTRANSFER => true,
]);

$response = curl_exec($curl);
if ($response === false) {
    throw new RuntimeException(curl_error($curl));
}
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);
if ($status >= 400) {
    throw new RuntimeException(sprintf("HCTI request failed (%d): %s", $status, $response));
}

$result = json_decode($response, true, 512, JSON_THROW_ON_ERROR);
printf("%s\n", $result["url"]);

Request configuration

Options used in this example

These values are sent with the HTML and CSS to control how HCTI loads the page and captures the final screenshot. You can change each one in the editor above.

Google Fonts

google_fonts
Inter
Google fonts to load. Separate multiple fonts with a pipe, such as 'Roboto|OpenSans', and set font-family in the CSS to use them.
Learn about this option

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