Modern JVM

Capture screenshots in Kotlin

Add screenshot and scrolling GIF capabilities to your Kotlin applications with OkHttp or ktor. No Selenium, no headless browsers to manage.

Installation

  1. 1Add OkHttp: implementation("com.squareup.okhttp3:okhttp:4.12.0")
  2. 2Get your API key from the dashboard
  3. 3Set the X-KEY header in your requests

Authentication

Include your API key in the X-KEY header with every request:

val client = OkHttpClient()
val request = Request.Builder()
    .url(url)
    .header("X-KEY", "your-api-key")
    .build()

Kotlin Screenshot Example

Capture a screenshot or create a scrolling GIF animation with a simple GET request:

Screenshot
import okhttp3.OkHttpClient
import okhttp3.Request
import java.io.File

fun main() {
    val client = OkHttpClient()
    val request = Request.Builder()
        .url("https://api.scrnpix.com/screenshot?url=https%3A%2F%2Fexample.com&width=1280&height=720&format=png")
        .header("X-KEY", "your-api-key")
        .build()

    client.newCall(request).execute().use { response ->
        File("screenshot.png").writeBytes(response.body!!.bytes())
    }
}
Animation
import okhttp3.OkHttpClient
import okhttp3.Request
import java.io.File

fun main() {
    val client = OkHttpClient()
    val request = Request.Builder()
        .url("https://api.scrnpix.com/animate?url=https%3A%2F%2Fexample.com&scroll_duration=3000&scroll_easing=ease-in-out")
        .header("X-KEY", "your-api-key")
        .build()

    client.newCall(request).execute().use { response ->
        File("animation.gif").writeBytes(response.body!!.bytes())
    }
}

Response Format

On success, the API returns the image binary data directly in the response body.

Status Code200 OK
Content-Typeimage/png, image/jpeg, or image/gif
BodyBinary image data (ByteArray)
Error ResponseError message with 4xx/5xx status

Key Features

Zero Setup

No need to install Selenium or manage headless Chrome. Just use OkHttp or ktor client.

Production Ready

Built on Cloudflare Workers with global edge network. Handles concurrency and browser lifecycle automatically.

Kotlin Integration

Idiomatic Kotlin with coroutines support. Integrates seamlessly with Ktor, Spring Boot, or Android apps.

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 Kotlin?

No. Scrnpix runs browsers on our infrastructure. You only need OkHttp or ktor to make HTTP calls.

Can I use this with Android or Ktor?

Yes. Scrnpix works with any Kotlin environment — Android apps, Ktor servers, Spring Boot, or plain Kotlin/JVM.

How do I handle errors in Kotlin?

Check the response code. A 200 status means success with image bytes in the body. Use Kotlin's try-catch or Result type for error handling.

What Kotlin version is required?

Any modern Kotlin version (1.5+) with OkHttp or ktor support. The API is a simple HTTP GET request.

Ready to capture screenshots in Kotlin?

Get your API key and start rendering screenshots in seconds. Free tier includes 50 screenshots per month.

Start Free