ScreenshotNeo

BlogComparisons

wkhtmltoimage Ruby Gem vs Direct Command Line: Which Should You Use?

Choose IMGKit for a Ruby API around wkhtmltoimage, or call the executable directly when you want to own subprocess handling. Both require a compatible renderer binary.

By the ScreenshotNeo team4 October 20268 min read

wkhtmltoimage is the renderer in both approaches. Use IMGKit when its Ruby API makes it easier to provide HTML, a URL, or a file and then retrieve image bytes or save an output. Call the wkhtmltoimage executable directly when you want your Ruby application to construct the command and own subprocess handling. IMGKit does not remove the need to install and configure a compatible executable.

The choice is about how Ruby integrates with the renderer and who manages command execution. The available documentation does not establish a performance winner.

What each approach does

IMGKit: a Ruby wrapper

IMGKit provides a Ruby interface to wkhtmltoimage. Its documented API accepts HTML, a URL, or a file, supports options understood by the executable, and can return image output or write it to a file. The renderer binary must still be available to the application.

Direct command-line invocation: your code runs the renderer

wkhtmltoimage is a standalone command-line utility for rendering HTML to image formats. Its documented invocation is wkhtmltoimage [OPTIONS]... <input file> <output file>. Ruby code can invoke it as a subprocess and handle arguments, output, and failures itself.

Decision guide

Question IMGKit Direct CLI
How do you call the renderer? Through a Ruby wrapper API. By invoking the executable as a subprocess.
Who owns command construction? The wrapper handles the integration; your code supplies inputs and options. Your code builds the argument list and manages process execution.
Can it accept HTML or a URL? The README documents HTML, URL, and file inputs. The executable takes an input and output path; consult its options for supported input forms.
Does it need wkhtmltoimage installed? Yes. IMGKit uses the executable. Yes. You invoke the executable directly.
Is one documented as faster? No comparison is established by the available documentation. No comparison is established by the available documentation.

Choose IMGKit if its Ruby-facing methods for setting options, getting output bytes, or writing a file fit your application. Choose direct invocation if your application already manages subprocesses and you prefer to pass command-line arguments yourself. In either case, pin and verify the binary used in each deployment environment.

Use IMGKit from Ruby

Install the gem and provide a compatible wkhtmltoimage executable separately, or use a documented binary package where it is suitable for your platform. The IMGKit README documents configuring the executable path. This example renders a URL and writes the returned image bytes to a file:

# Gemfile
 gem "imgkit"
# render.rb
require "imgkit"

# Configure this path to the wkhtmltoimage executable installed in your environment.
IMGKit.configure do |config|
  config.wkhtmltoimage = "/usr/local/bin/wkhtmltoimage"
end

kit = IMGKit.new("https://example.com", quality: 90)
File.binwrite("page.png", kit.to_img(:png))

Use a path that exists in the runtime environment, not just on a developer workstation. IMGKit accepts renderer options; check the wrapper and executable documentation for the option names and supported values you need.

Call wkhtmltoimage directly from Ruby

This example uses Ruby’s Open3.capture3 to pass an argument array to the process, inspect its exit status, and report stderr if rendering fails. The input HTML and output image are files so the command follows the documented input/output form.

# direct_render.rb
require "open3"
require "tempfile"

binary = "/usr/local/bin/wkhtmltoimage"
html = <<~HTML
  <!doctype html>
  <html><head><meta charset="utf-8"><title>Example</title></head>
  <body><h1>Rendered by wkhtmltoimage</h1></body></html>
HTML

Tempfile.create(["page", ".html"]) do |input|
  input.write(html)
  input.flush

  stdout, stderr, status = Open3.capture3(
    binary,
    "--format", "png",
    input.path,
    "page.png"
  )

  unless status.success?
    abort "wkhtmltoimage failed (#{status.exitstatus}): #{stderr}"
  end
end

Passing each argument separately avoids shell interpolation of paths and options. Adapt the option list to the executable version installed in your environment. For production code, also set an execution timeout and ensure temporary input files are cleaned up if your process is interrupted.

Install and configure the executable

  1. Select the packaging route. IMGKit’s README describes installing the binary separately, using a binary gem, or configuring an explicit executable path. Direct CLI use also requires an installed executable.
  2. Match the package to the deployment target. The wkhtmltoimage-binary 0.12.5 package describes Linux and Mac binaries and was released on 15 August 2018. The Ubuntu Noble manual documents package version 0.12.6-2build2. These are different packaging contexts; do not assume their builds are interchangeable.
  3. Check the path at runtime. For IMGKit, configure the executable path if it is not discoverable by the application. For direct invocation, use the intended binary path in the subprocess call.
  4. Verify the actual deployment environment. The documented binary package describes Linux and Mac support, and IMGKit examples show Linux and macOS x86_64 paths. Those examples do not guarantee support for every current operating system, architecture, or Ruby runtime.

Record the package source, version, operating system, and architecture used by each deployed environment. The available sources do not establish that different builds behave identically.

Options and input handling

IMGKit documents accepting options understood by wkhtmltoimage. With direct invocation, supply the renderer’s options as command-line arguments. The Ubuntu manual lists the command synopsis and options; consult it alongside the documentation for the exact binary you install, because packaging contexts and versions differ.

  • Input: IMGKit documents HTML, URL, and file inputs. Direct invocation takes an input and output argument; use the renderer’s documented input support and options for your installed version.
  • Output format: Select a format supported by the executable and ensure the output filename and format option agree. IMGKit’s README demonstrates selecting image output and writing a file.
  • Quality and other renderer settings: IMGKit documents setting options such as image quality and forwarding options understood by the executable. Direct calls pass those options as CLI arguments.
  • Paths with spaces or special characters: With direct Ruby subprocess calls, pass an argument array rather than building a shell command string. This keeps paths as individual arguments.
  • Untrusted or user-provided input: Treat input URLs and HTML as application data. Avoid interpolating them into a shell string; validate inputs and pass arguments separately.

For the complete option list and syntax, use the Ubuntu Noble wkhtmltoimage manual as a version-specific reference and check the documentation for your installed build.

When you need cURL, Python, or Node.js

Those languages do not choose between a Ruby wrapper and a Ruby subprocess. If your actual goal is to request a website screenshot from an API instead of installing and running the browser renderer yourself, ScreenshotNeo provides a one-request option. See the ScreenshotNeo API documentation for its request parameters.

cURL

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
const bytes = Buffer.from(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('shot.webp', bytes));

Or skip the browser setup

ScreenshotNeo takes a screenshot with one GET request. Cookie banners are accepted and removed before the capture, along with known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the API documentation for options. ScreenshotNeo also supports full-page and element captures, device and viewport settings, image and PDF output, custom waits, request blocking, and asynchronous jobs. Sign up for 1,000 free screenshots a month with no card.

Performance, reliability, and cost

Performance

The cited documentation does not provide a comparative benchmark for IMGKit versus direct invocation. Both approaches use the same renderer dependency, so choose based on integration needs and measure in your own deployment if rendering time matters. Input page complexity, renderer options, and the environment should be held consistent in any internal comparison.

Reliability

Both routes depend on a compatible executable being present and runnable. A missing path, incompatible package, or unsupported deployment target can prevent rendering regardless of whether IMGKit or a subprocess is used. Direct invocation makes your Ruby code responsible for process exit status and diagnostics; IMGKit provides wrapper methods but still depends on the renderer.

Cost and maintenance

The research dossier establishes no comparative hosting or operating cost. With either self-managed approach, account for installing and updating the executable in each environment, verifying compatibility, and handling failures. Binary package versions in the sources differ, so identify and pin the package you deploy rather than assuming a gem wrapper determines the renderer version.

Troubleshooting

Symptom Likely cause What to check or change
IMGKit cannot find or start wkhtmltoimage The executable is absent, not executable, or not at the configured path. Install a compatible binary and configure IMGKit with its actual path. Confirm that the application runtime can execute it.
Direct Ruby invocation reports a missing file The binary path or input path is wrong, or the process has a different working directory than expected. Use explicit paths and check that the files exist and are accessible to the application process.
The command exits unsuccessfully The input, output path, option syntax, or runtime environment may not be accepted by that build. Capture stderr and exit status, verify the command against the installed version’s manual, and try the same invocation outside the application.
Works locally but fails after deployment The deployed OS, architecture, Ruby runtime, package, or executable path differs. Inspect the deployed package and architecture; install a compatible build and configure its path explicitly.
Output format or quality is unexpected The requested option may be missing, unsupported, or inconsistent with the output path. Check the relevant option in the installed executable’s documentation and set the format and quality explicitly.
Paths containing spaces fail in direct mode A command string may have been split or interpreted by a shell. Pass the binary and each option/path as separate arguments, as in the Open3 example.

FAQ

Does IMGKit include wkhtmltoimage?

IMGKit is a Ruby wrapper that uses the executable. Its documentation describes supplying the binary separately or configuring its path.

Can I use IMGKit without a Ruby application?

IMGKit is the Ruby integration. For other languages or shell scripts, invoke the executable through that environment’s process interface, or use a screenshot API.

Which one should I choose if I already manage subprocesses?

Direct invocation is a natural fit when your application already owns process execution and you want to pass CLI arguments directly. Use IMGKit when its Ruby API simplifies your code.

Are the 0.12.5 binary gem and Ubuntu’s 0.12.6-2build2 package interchangeable?

The sources describe different packaging contexts and do not establish interchangeability. Check the build, platform, and runtime you deploy.