Capture screenshots in Zig
Add screenshot and scrolling GIF capabilities to your Zig applications with std.http.Client. Zero hidden allocations, no headless browsers to manage.
Installation
- 1std.http.Client is included in Zig standard library
- 2Get your API key from the dashboard
- 3Set the X-KEY header in your requests
Authentication
Include your API key in the X-KEY header with every request:
const std = @import("std");
var client = std.http.Client{ .allocator = allocator };
var headers = std.http.Headers{ .allocator = allocator };
try headers.append("X-KEY", "your-api-key");Zig Screenshot Example
Capture a screenshot or create a scrolling GIF animation with a simple GET request:
const std = @import("std");
pub fn main() !void {
var client = std.http.Client{ .allocator = std.heap.page_allocator };
defer client.deinit();
var headers = std.http.Headers{ .allocator = std.heap.page_allocator };
try headers.append("X-KEY", "your-api-key");
const uri = try std.Uri.parse("https://api.scrnpix.com/screenshot?url=https%3A%2F%2Fexample.com&width=1280&height=720&format=png");
var req = try client.request(.GET, uri, headers, .{});
defer req.deinit();
try req.wait();
const body = try req.reader().readAllAlloc(std.heap.page_allocator, 10_000_000);
const file = try std.fs.cwd().createFile("screenshot.png", .{});
defer file.close();
try file.writeAll(body);
}const std = @import("std");
pub fn main() !void {
var client = std.http.Client{ .allocator = std.heap.page_allocator };
defer client.deinit();
var headers = std.http.Headers{ .allocator = std.heap.page_allocator };
try headers.append("X-KEY", "your-api-key");
const uri = try std.Uri.parse("https://api.scrnpix.com/animate?url=https%3A%2F%2Fexample.com&scroll_duration=3000&scroll_easing=ease-in-out");
var req = try client.request(.GET, uri, headers, .{});
defer req.deinit();
try req.wait();
const body = try req.reader().readAllAlloc(std.heap.page_allocator, 10_000_000);
const file = try std.fs.cwd().createFile("animation.gif", .{});
defer file.close();
try file.writeAll(body);
}Response Format
On success, the API returns the image binary data directly in the response body.
| Status Code | 200 OK |
| Content-Type | image/png, image/jpeg, or image/gif |
| Body | Binary image data ([]u8) |
| Error Response | Error message with 4xx/5xx status |
Key Features
Zero Setup
std.http.Client is built into Zig. No external dependencies or browser installations required.
Production Ready
Built on Cloudflare Workers with global edge network. Handles concurrency and browser lifecycle automatically.
Zig Integration
Manual memory control with comptime. Perfect for embedded systems, WASM, or performance-critical applications.
Rich Features
Custom viewport sizes, full page capture, PNG/JPEG formats, scrolling GIFs with 15 easing functions.
Frequently Asked Questions
Do I need to install any browser dependencies for Zig?
No. Scrnpix runs browsers on our infrastructure. You only need Zig's built-in std.http.Client to make HTTP calls.
Can I use this with Zig for WASM or embedded?
Yes. Scrnpix works with any Zig target — native applications, WASM modules, or embedded systems with network access.
How do I handle errors in Zig?
Use try/catch with error unions. A 200 status means success with image bytes in the response reader.
What Zig version is required?
Zig 0.11+ with std.http.Client support. The API is a simple HTTP GET request.
Ready to capture screenshots in Zig?
Get your API key and start rendering screenshots in seconds. Free tier includes 50 screenshots per month.
Start Free