Rust: HTML/CSS to Image
Generate Images and PDFs with Rust. Renders exactly like Google Chrome.
Render PNG, JPG, or WebP images + PDFs with Rust from HTML/CSS or reusable dynamic templates.
Generating images with Rust
- The API takes your HTML/CSS and runs it inside a real instance of Google Chrome to convert your HTML into an image.
- Use Rust to send the API your HTML/CSS.
- You’ll get back JSON with the URL to your generated image.
For more details on how this works, see Creating an image.
Example API response:
{
"url": "https://hcti.io/v1/image/be4c5118-fe19-462b-a49e-48cf72697a9d",
"id": "be4c5118-fe19-462b-a49e-48cf72697a9d"
}

Authentication with Rust
The API uses HTTP Basic authentication.
Your username is your User ID and your password is your API Key. Both of these are available from the dashboard. The Rust code sample demonstrates how to authenticate your request.
You can sign up for a free API key to get started.
Rust example code
This Rust code example sends an HTTP POST to the https://hcti.io/v1/image API to convert your HTML/CSS to an image.
Rust’s standard library does not include an HTTP client. This example uses reqwest for HTTP and serde_json to build the JSON request body.
Add the dependencies to your Cargo.toml:
[dependencies]
reqwest = { version = "0.12", features = ["blocking", "json"] }
serde_json = "1"
use serde_json::json;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let user_id = "your-user-id";
let api_key = "your-api-key";
let client = reqwest::blocking::Client::new();
let payload = json!({
"html": "<div class='box'>Rust ✅</div>",
"css": ".box { border: 4px solid #03B875; padding: 20px; font-family: Roboto, sans-serif; }",
"google_fonts": "Roboto"
});
let response = client
.post("https://hcti.io/v1/image")
.basic_auth(user_id, Some(api_key))
.json(&payload)
.send()?
.error_for_status()?;
let body = response.text()?;
println!("{body}");
// {"url":"https://hcti.io/v1/image/1113184e-419f-49f1-b231-2069942a186f"}
Ok(())
}
Need help?
Talk to a human. Please email us support@htmlcsstoimage.com with any questions and we’ll gladly help you get started.