Rust icon

Rust

Generate images from a template with ureq and serde_json. Imejis returns the finished image directly in the response, so there is nothing to poll and no webhook to receive.

Set two environment variables first: IMEJIS_API_KEY (from your dashboard) and IMEJIS_DESIGN_ID (any design's id). Then send the fields you want to change as component.property pairs: headline.text, title.color, image.image. Only the fields you send change; everything else keeps its designed value, and a design's overridable fields are listed in its Share / API panel.

Every block below is a copy-paste runnable program, and every one of them is executed in Docker against a real render service before it ships.

Generate a single imageGenerate a single image

One POST, one image. The response body is the rendered image itself, with nothing to poll and no webhook to receive.

Rust: Generate a single image
use serde_json::{json, Value};
use std::env;
use std::fs;
use std::io::Read;
 
fn env_or(key: &str, fallback: &str) -> String {
    match env::var(key) {
        Ok(value) if !value.is_empty() => value,
        _ => fallback.to_string(),
    }
}
 
/// POST a JSON body to `path` with the render key; returns (status, bytes, content-type).
fn render(path: &str, query: &str, body: Value) -> (u16, Vec<u8>, String) {
    let base = env_or("IMEJIS_RENDER_URL", "https://render.imejis.io");
    let api_key = env::var("IMEJIS_API_KEY").expect("IMEJIS_API_KEY");
    let url = if query.is_empty() {
        format!("{base}{path}")
    } else {
        format!("{base}{path}?{query}")
    };
    let response = ureq::post(&url)
        .set("dma-api-key", &api_key)
        .set("Content-Type", "application/json")
        .send_string(&body.to_string())
        .expect("render request failed");
    let status = response.status();
    let content_type = response.content_type().to_string();
    let mut bytes = Vec::new();
    response
        .into_reader()
        .read_to_end(&mut bytes)
        .expect("read body");
    (status, bytes, content_type)
}
 
/// The size to render on a multi-size design; absent/"master" is the base.
fn variation() -> String {
    env_or("IMEJIS_VARIATION_ID", "story")
}
 
/// Percent-encode a query value (spaces, #, unicode all have to be escaped).
fn encode(value: &str) -> String {
    value
        .bytes()
        .map(|b| match b {
            b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
                (b as char).to_string()
            }
            _ => format!("%{b:02X}"),
        })
        .collect()
}
fn main() {
    let design_id = env::var("IMEJIS_DESIGN_ID").expect("IMEJIS_DESIGN_ID");
 
    // Render one image. The response body IS the image — no polling, no webhook.
    let (status, image, _) = render(
        &format!("/v1/{design_id}"),
        "",
        json!({
            "headline.text": "Hello from Rust",
            "subtitle.text": "Rendered in one request",
        }),
    );
    fs::write("output.jpg", &image).expect("write output.jpg");
    println!("single: {status} {} bytes", image.len());
}

Every output format png jpeg webp and pdfEvery output format: PNG, JPEG, WebP and PDF

Pick the output with ?format=. PNG and WebP keep transparency, JPEG is the smallest lossy option, and PDF is a single print-ready page. ?quality= applies to JPEG only.

Rust: Every output format: PNG, JPEG, WebP and PDF
use serde_json::{json, Value};
use std::env;
use std::fs;
use std::io::Read;
 
fn env_or(key: &str, fallback: &str) -> String {
    match env::var(key) {
        Ok(value) if !value.is_empty() => value,
        _ => fallback.to_string(),
    }
}
 
/// POST a JSON body to `path` with the render key; returns (status, bytes, content-type).
fn render(path: &str, query: &str, body: Value) -> (u16, Vec<u8>, String) {
    let base = env_or("IMEJIS_RENDER_URL", "https://render.imejis.io");
    let api_key = env::var("IMEJIS_API_KEY").expect("IMEJIS_API_KEY");
    let url = if query.is_empty() {
        format!("{base}{path}")
    } else {
        format!("{base}{path}?{query}")
    };
    let response = ureq::post(&url)
        .set("dma-api-key", &api_key)
        .set("Content-Type", "application/json")
        .send_string(&body.to_string())
        .expect("render request failed");
    let status = response.status();
    let content_type = response.content_type().to_string();
    let mut bytes = Vec::new();
    response
        .into_reader()
        .read_to_end(&mut bytes)
        .expect("read body");
    (status, bytes, content_type)
}
 
/// The size to render on a multi-size design; absent/"master" is the base.
fn variation() -> String {
    env_or("IMEJIS_VARIATION_ID", "story")
}
 
/// Percent-encode a query value (spaces, #, unicode all have to be escaped).
fn encode(value: &str) -> String {
    value
        .bytes()
        .map(|b| match b {
            b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
                (b as char).to_string()
            }
            _ => format!("%{b:02X}"),
        })
        .collect()
}
fn main() {
    let design_id = env::var("IMEJIS_DESIGN_ID").expect("IMEJIS_DESIGN_ID");
 
    // Every output format, with JPEG quality. PNG and WebP keep transparency;
    // PDF is a single print-ready page. quality only affects JPEG.
    for format in ["png", "jpeg", "webp", "pdf"] {
        let query = if format == "jpeg" {
            format!("format={format}&quality=85")
        } else {
            format!("format={format}")
        };
        let (_, bytes, content_type) = render(
            &format!("/v1/{design_id}"),
            &query,
            json!({ "headline.text": format!("Format: {format}") }),
        );
        fs::write(format!("output.{format}"), &bytes).expect("write output");
        println!("formats: {format} {content_type} {}", bytes.len());
    }
}

Render multiple sizes from one templateRender multiple sizes from one template

A multi-size design carries several canvases: an OG image, a square post, a vertical story. ?variation=<id> picks which one you get back; omit it for the base size.

Rust: Render multiple sizes from one template
use serde_json::{json, Value};
use std::env;
use std::fs;
use std::io::Read;
 
fn env_or(key: &str, fallback: &str) -> String {
    match env::var(key) {
        Ok(value) if !value.is_empty() => value,
        _ => fallback.to_string(),
    }
}
 
/// POST a JSON body to `path` with the render key; returns (status, bytes, content-type).
fn render(path: &str, query: &str, body: Value) -> (u16, Vec<u8>, String) {
    let base = env_or("IMEJIS_RENDER_URL", "https://render.imejis.io");
    let api_key = env::var("IMEJIS_API_KEY").expect("IMEJIS_API_KEY");
    let url = if query.is_empty() {
        format!("{base}{path}")
    } else {
        format!("{base}{path}?{query}")
    };
    let response = ureq::post(&url)
        .set("dma-api-key", &api_key)
        .set("Content-Type", "application/json")
        .send_string(&body.to_string())
        .expect("render request failed");
    let status = response.status();
    let content_type = response.content_type().to_string();
    let mut bytes = Vec::new();
    response
        .into_reader()
        .read_to_end(&mut bytes)
        .expect("read body");
    (status, bytes, content_type)
}
 
/// The size to render on a multi-size design; absent/"master" is the base.
fn variation() -> String {
    env_or("IMEJIS_VARIATION_ID", "story")
}
 
/// Percent-encode a query value (spaces, #, unicode all have to be escaped).
fn encode(value: &str) -> String {
    value
        .bytes()
        .map(|b| match b {
            b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
                (b as char).to_string()
            }
            _ => format!("%{b:02X}"),
        })
        .collect()
}
fn main() {
    let design_id = env::var("IMEJIS_DESIGN_ID").expect("IMEJIS_DESIGN_ID");
 
    // One template, many sizes. ?variation=<id> picks the size; omit it for the
    // base. The ids are listed in the design's Share / API panel.
    let (status, sized, _) = render(
        &format!("/v1/{design_id}"),
        &format!("format=png&variation={}", encode(&variation())),
        json!({ "headline.text": "Story size" }),
    );
    println!("variation: {status} {} bytes", sized.len());
}

An image url for img tags email and thumbnailsAn image URL for <img> tags, email and thumbnails

The same render as a plain GET URL, with the field values in the query string. Drop it into an <img src>, an HTML email, or a Slack message and it renders fresh every time it is fetched.

Rust: An image URL for img tags, email and thumbnails
use serde_json::{json, Value};
use std::env;
use std::fs;
use std::io::Read;
 
fn env_or(key: &str, fallback: &str) -> String {
    match env::var(key) {
        Ok(value) if !value.is_empty() => value,
        _ => fallback.to_string(),
    }
}
 
/// POST a JSON body to `path` with the render key; returns (status, bytes, content-type).
fn render(path: &str, query: &str, body: Value) -> (u16, Vec<u8>, String) {
    let base = env_or("IMEJIS_RENDER_URL", "https://render.imejis.io");
    let api_key = env::var("IMEJIS_API_KEY").expect("IMEJIS_API_KEY");
    let url = if query.is_empty() {
        format!("{base}{path}")
    } else {
        format!("{base}{path}?{query}")
    };
    let response = ureq::post(&url)
        .set("dma-api-key", &api_key)
        .set("Content-Type", "application/json")
        .send_string(&body.to_string())
        .expect("render request failed");
    let status = response.status();
    let content_type = response.content_type().to_string();
    let mut bytes = Vec::new();
    response
        .into_reader()
        .read_to_end(&mut bytes)
        .expect("read body");
    (status, bytes, content_type)
}
 
/// The size to render on a multi-size design; absent/"master" is the base.
fn variation() -> String {
    env_or("IMEJIS_VARIATION_ID", "story")
}
 
/// Percent-encode a query value (spaces, #, unicode all have to be escaped).
fn encode(value: &str) -> String {
    value
        .bytes()
        .map(|b| match b {
            b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
                (b as char).to_string()
            }
            _ => format!("%{b:02X}"),
        })
        .collect()
}
fn main() {
    let design_id = env::var("IMEJIS_DESIGN_ID").expect("IMEJIS_DESIGN_ID");
 
    // The same render as a plain GET URL — drop it into an <img> tag, an HTML
    // email, or a Slack message. Field overrides ride the query string.
    let base = env_or("IMEJIS_RENDER_URL", "https://render.imejis.io");
    let api_key = env::var("IMEJIS_API_KEY").expect("IMEJIS_API_KEY");
    let get_url = format!(
        "{base}/v1/{design_id}?dma-api-key={}&format=png&headline.text={}&subtitle.text={}",
        encode(&api_key),
        encode("Hello from a URL"),
        encode("No request body needed"),
    );
    println!("get: {get_url}");
    let via_url = ureq::get(&get_url).call().expect("GET render failed");
    let status = via_url.status();
    let mut url_bytes = Vec::new();
    via_url
        .into_reader()
        .read_to_end(&mut url_bytes)
        .expect("read body");
    println!("get: {status} {} bytes", url_bytes.len());
}

Hosted delivery get a public image url backHosted delivery: get a public image URL back

?delivery=hosted stores the render and returns a public URL instead of raw bytes, which is what an email, a webhook payload, or a dashboard needs: a link rather than a file.

Rust: Hosted delivery: get a public image URL back
use serde_json::{json, Value};
use std::env;
use std::fs;
use std::io::Read;
 
fn env_or(key: &str, fallback: &str) -> String {
    match env::var(key) {
        Ok(value) if !value.is_empty() => value,
        _ => fallback.to_string(),
    }
}
 
/// POST a JSON body to `path` with the render key; returns (status, bytes, content-type).
fn render(path: &str, query: &str, body: Value) -> (u16, Vec<u8>, String) {
    let base = env_or("IMEJIS_RENDER_URL", "https://render.imejis.io");
    let api_key = env::var("IMEJIS_API_KEY").expect("IMEJIS_API_KEY");
    let url = if query.is_empty() {
        format!("{base}{path}")
    } else {
        format!("{base}{path}?{query}")
    };
    let response = ureq::post(&url)
        .set("dma-api-key", &api_key)
        .set("Content-Type", "application/json")
        .send_string(&body.to_string())
        .expect("render request failed");
    let status = response.status();
    let content_type = response.content_type().to_string();
    let mut bytes = Vec::new();
    response
        .into_reader()
        .read_to_end(&mut bytes)
        .expect("read body");
    (status, bytes, content_type)
}
 
/// The size to render on a multi-size design; absent/"master" is the base.
fn variation() -> String {
    env_or("IMEJIS_VARIATION_ID", "story")
}
 
/// Percent-encode a query value (spaces, #, unicode all have to be escaped).
fn encode(value: &str) -> String {
    value
        .bytes()
        .map(|b| match b {
            b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
                (b as char).to_string()
            }
            _ => format!("%{b:02X}"),
        })
        .collect()
}
fn main() {
    let design_id = env::var("IMEJIS_DESIGN_ID").expect("IMEJIS_DESIGN_ID");
 
    // delivery=hosted stores the render and returns a PUBLIC URL instead of
    // bytes — for an email, a webhook payload, or a dashboard that needs a link.
    let (_, body, _) = render(
        &format!("/v1/{design_id}"),
        "delivery=hosted&format=png",
        json!({ "headline.text": "Hosted delivery" }),
    );
    let hosted: Value = serde_json::from_slice(&body).expect("parse hosted json");
    println!(
        "hosted: {} {} bytes",
        hosted["url"].as_str().unwrap_or_default(),
        hosted["file"]["size"]
    );
}

Signed delivery a private expiring image urlSigned delivery: a private, expiring image URL

?delivery=signed stores the render privately and returns a time-limited signed URL. ?expiresIn= is minutes.

Rust: Signed delivery: a private, expiring image URL
use serde_json::{json, Value};
use std::env;
use std::fs;
use std::io::Read;
 
fn env_or(key: &str, fallback: &str) -> String {
    match env::var(key) {
        Ok(value) if !value.is_empty() => value,
        _ => fallback.to_string(),
    }
}
 
/// POST a JSON body to `path` with the render key; returns (status, bytes, content-type).
fn render(path: &str, query: &str, body: Value) -> (u16, Vec<u8>, String) {
    let base = env_or("IMEJIS_RENDER_URL", "https://render.imejis.io");
    let api_key = env::var("IMEJIS_API_KEY").expect("IMEJIS_API_KEY");
    let url = if query.is_empty() {
        format!("{base}{path}")
    } else {
        format!("{base}{path}?{query}")
    };
    let response = ureq::post(&url)
        .set("dma-api-key", &api_key)
        .set("Content-Type", "application/json")
        .send_string(&body.to_string())
        .expect("render request failed");
    let status = response.status();
    let content_type = response.content_type().to_string();
    let mut bytes = Vec::new();
    response
        .into_reader()
        .read_to_end(&mut bytes)
        .expect("read body");
    (status, bytes, content_type)
}
 
/// The size to render on a multi-size design; absent/"master" is the base.
fn variation() -> String {
    env_or("IMEJIS_VARIATION_ID", "story")
}
 
/// Percent-encode a query value (spaces, #, unicode all have to be escaped).
fn encode(value: &str) -> String {
    value
        .bytes()
        .map(|b| match b {
            b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
                (b as char).to_string()
            }
            _ => format!("%{b:02X}"),
        })
        .collect()
}
fn main() {
    let design_id = env::var("IMEJIS_DESIGN_ID").expect("IMEJIS_DESIGN_ID");
 
    // delivery=signed stores it privately and returns a time-limited signed
    // URL. expiresIn is minutes (default 60, max 7 days).
    let (_, body, _) = render(
        &format!("/v1/{design_id}"),
        "delivery=signed&format=png&expiresIn=30",
        json!({ "headline.text": "Signed delivery" }),
    );
    let signed: Value = serde_json::from_slice(&body).expect("parse signed json");
    let url = signed["url"].as_str().unwrap_or_default();
    println!(
        "signed: {} {}...",
        signed["expiresAt"].as_str().unwrap_or_default(),
        &url[..url.len().min(80)]
    );
}

Bulk image generation in one callBulk image generation in one call

POST /bulk to render many images in a single request: several sizes, several data variants, a mix of designs, or the ordered slides of a carousel. results preserves input order, so results[i] is items[i].

Rust: Bulk image generation in one call
use serde_json::{json, Value};
use std::env;
use std::fs;
use std::io::Read;
 
fn env_or(key: &str, fallback: &str) -> String {
    match env::var(key) {
        Ok(value) if !value.is_empty() => value,
        _ => fallback.to_string(),
    }
}
 
/// POST a JSON body to `path` with the render key; returns (status, bytes, content-type).
fn render(path: &str, query: &str, body: Value) -> (u16, Vec<u8>, String) {
    let base = env_or("IMEJIS_RENDER_URL", "https://render.imejis.io");
    let api_key = env::var("IMEJIS_API_KEY").expect("IMEJIS_API_KEY");
    let url = if query.is_empty() {
        format!("{base}{path}")
    } else {
        format!("{base}{path}?{query}")
    };
    let response = ureq::post(&url)
        .set("dma-api-key", &api_key)
        .set("Content-Type", "application/json")
        .send_string(&body.to_string())
        .expect("render request failed");
    let status = response.status();
    let content_type = response.content_type().to_string();
    let mut bytes = Vec::new();
    response
        .into_reader()
        .read_to_end(&mut bytes)
        .expect("read body");
    (status, bytes, content_type)
}
 
/// The size to render on a multi-size design; absent/"master" is the base.
fn variation() -> String {
    env_or("IMEJIS_VARIATION_ID", "story")
}
 
/// Percent-encode a query value (spaces, #, unicode all have to be escaped).
fn encode(value: &str) -> String {
    value
        .bytes()
        .map(|b| match b {
            b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
                (b as char).to_string()
            }
            _ => format!("%{b:02X}"),
        })
        .collect()
}
fn main() {
    let design_id = env::var("IMEJIS_DESIGN_ID").expect("IMEJIS_DESIGN_ID");
 
    // Many images in ONE call. results keeps input order, so results[i] is
    // items[i] — for a carousel the array IS the slide order. Each item is one
    // metered render, and a failed item does not abort the rest.
    let (_, body, _) = render(
        "/bulk",
        "",
        json!({
            "delivery": "hosted",
            "format": "png",
            "items": [
                { "designId": design_id, "overrides": { "headline.text": "Slide 1" } },
                { "designId": design_id, "variation": variation(), "format": "jpeg",
                  "quality": 80, "overrides": { "headline.text": "Slide 2" } },
                { "designId": design_id, "format": "pdf",
                  "overrides": { "headline.text": "Slide 3" } },
            ],
        }),
    );
    let bulk: Value = serde_json::from_slice(&body).expect("parse bulk json");
    println!("bulk: {}", bulk["summary"]);
    for item in bulk["results"].as_array().unwrap_or(&vec![]) {
        let target = item["url"].as_str().or(item["error"].as_str()).unwrap_or("");
        println!("   {} {} {target}", item["index"], item["format"]);
    }
}

Bulk from a list of rowsBulk from a list of rows

Send data instead of items and every row becomes one render, with no item list to build. That is the shape to reach for when the input is a spreadsheet, a database query, or a CSV.

Rust: Bulk from a list of rows
use serde_json::{json, Value};
use std::env;
use std::fs;
use std::io::Read;
 
fn env_or(key: &str, fallback: &str) -> String {
    match env::var(key) {
        Ok(value) if !value.is_empty() => value,
        _ => fallback.to_string(),
    }
}
 
/// POST a JSON body to `path` with the render key; returns (status, bytes, content-type).
fn render(path: &str, query: &str, body: Value) -> (u16, Vec<u8>, String) {
    let base = env_or("IMEJIS_RENDER_URL", "https://render.imejis.io");
    let api_key = env::var("IMEJIS_API_KEY").expect("IMEJIS_API_KEY");
    let url = if query.is_empty() {
        format!("{base}{path}")
    } else {
        format!("{base}{path}?{query}")
    };
    let response = ureq::post(&url)
        .set("dma-api-key", &api_key)
        .set("Content-Type", "application/json")
        .send_string(&body.to_string())
        .expect("render request failed");
    let status = response.status();
    let content_type = response.content_type().to_string();
    let mut bytes = Vec::new();
    response
        .into_reader()
        .read_to_end(&mut bytes)
        .expect("read body");
    (status, bytes, content_type)
}
 
/// The size to render on a multi-size design; absent/"master" is the base.
fn variation() -> String {
    env_or("IMEJIS_VARIATION_ID", "story")
}
 
/// Percent-encode a query value (spaces, #, unicode all have to be escaped).
fn encode(value: &str) -> String {
    value
        .bytes()
        .map(|b| match b {
            b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
                (b as char).to_string()
            }
            _ => format!("%{b:02X}"),
        })
        .collect()
}
fn main() {
    let design_id = env::var("IMEJIS_DESIGN_ID").expect("IMEJIS_DESIGN_ID");
 
    // The same design over a LIST OF ROWS — one render per row, no items[] to
    // build. Use "variations": ["master","story"] instead to render every SIZE.
    let (_, body, _) = render(
        "/bulk",
        "",
        json!({
            "designId": design_id,
            "delivery": "signed",
            "expiresIn": 15,
            "format": "png",
            "data": [
                { "headline.text": "Ada Lovelace", "subtitle.text": "Mathematician" },
                { "headline.text": "Alan Turing", "subtitle.text": "Computer scientist" },
                { "headline.text": "Grace Hopper", "subtitle.text": "Rear admiral" },
            ],
        }),
    );
    let rows: Value = serde_json::from_slice(&body).expect("parse bulk json");
    println!("bulk-data: {}", rows["summary"]);
}

The response is the raw image (`image/jpeg` by default). Choose the format with `?format=png|jpeg|webp|pdf` (default jpeg) and set JPEG quality with `?quality=1-100`. Store the result and get a URL back with `?delivery=hosted` (or `?delivery=signed&expiresIn=60`), and render a specific size of a multi-size design with `?variation=<id>`.

ParameterValuesDefaultWhat it does
?format=png · jpeg · webp · pdfjpegOutput image format.
?quality=1–100noneCompression quality for lossy output; ignored for other formats. (JPEG only)
?delivery=stream · hosted · signedstreamstream = raw image bytes (default); hosted = store + return a public URL; signed = store + return a time-limited URL.
?expiresIn=minutes60Signed-URL lifetime in minutes (default 60, max 10080 = 7 days). (delivery=signed only)
?variation=<size id>masterWhich multi-dimension SIZE to render. Omit or use "master" for the base size; an unknown id falls back to the master. (multi-size designs only)
  • PNG (?format=png): Lossless, supports transparency. Largest file.
  • JPEG (?format=jpeg): Smaller, lossy, no transparency. Quality adjustable.
  • WebP (?format=webp): Smallest, supports transparency. Modern browsers.
  • PDF (?format=pdf): Vector page, for print and documents.

See the delivery modes and generate images with the API guides.

No Rust framework page exists yet; the cURL page is the clearest reference for the requests themselves. ureq is blocking by design, so call it from a worker rather than inside an async runtime, or swap in reqwest where you need futures. Each call is one render, 100 free a month, then pricing.