Guides · Ruby · Net::HTTP

Capture very tall pages as numbered tiles in Ruby with Net::HTTP

A single image has a height cap (20,000 CSS px) because somewhere past that, image viewers and memory both give up. "tile": true is the opt-in for pages that run past it: instead of cutting the capture off, the API returns a ZIP of numbered PNG tiles that cover the entire document.

Below is a complete, runnable Ruby program using Net::HTTP, no third-party dependency needed. It reads your API key from the SNAPDOK_KEY environment variable — free keys take about thirty seconds and need no card.

require "json"
require "net/http"
require "uri"

uri = URI("https://snapdok.io/v1/render")

res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 90) do |http|
  req = Net::HTTP::Post.new(uri)
  req["Authorization"] = "Bearer #{ENV.fetch("SNAPDOK_KEY")}"
  req["Content-Type"] = "application/json"
  req.body = JSON.generate({
    url: "https://your-app.com/changelog",
    format: "png",
    full_page: true,
    tile: true,
})
  http.request(req)
end

raise "snapdok error #{res.code}: #{res.body}" unless res.is_a?(Net::HTTPSuccess)

File.binwrite("page-tiles.zip", res.body)
puts "#{res["X-Tiles"]}  # how many parts are in the ZIP"

The tiles overlap on purpose: each part starts 80 px above where the previous one ended, so the seam appears in both images and nothing can fall into a gap — line up the repeated rows and you have the whole page. The archive includes a README stating each part's y-range, and the response carries the numbers too: X-Tiles (count), X-Tile-Overlap (the 80 px), and X-Page-Height.

Note the response type changes: with tiling you receive application/zip, not image/png — code that assumes an image must branch on Content-Type. Pages short enough for one image return a plain PNG even with tile set, so the branch is required, not theoretical. That asymmetry is deliberate: a screenshot is one image to almost everyone, so the archive only happens when you asked for it and the page needs it.

Same endpoint, one more trick: if the page you are rendering has a form on it, adding "pdf_forms": true to a PDF render brings it back with real, fillable AcroForm fields — a PDF people can type into, not a picture of one. How that works.

Notes for Net::HTTP

Stdlib only — no gems. The traps Net::HTTP is famous for, all handled in the sample: TLS is not automatic (set use_ssl: true or you will POST in the clear to port 80 and get a redirect); the default read_timeout of 60 s is close enough to real render times that raising it is wise; and the response body is a binary-ready String, but write it with File.binwrite — plain File.write on Windows would mangle line-ending bytes in the PDF. Check is_a?(Net::HTTPSuccess): Net::HTTP never raises on HTTP error statuses.

Response headers worth reading

HeaderMeaning
Content-Typeapplication/zip when tiled, image/png when not needed.
X-TilesNumber of parts in the archive.
X-Tile-OverlapVertical overlap between parts, in CSS px.

Full parameter reference: the docs. Hard numbers on caps and timeouts: limits.

Related guides

Same task, other stacks

More with Ruby + Net::HTTP