Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Python IMGKit does not use a no-background option for images. To create a transparent result, pass wkhtmltoimage’s transparent flag and save the output as PNG (or SVG where your renderer supports it): {"format": "png", "transparent": ""}. The flag makes the renderer’s white canvas transparent; it does not remove arbitrary colored CSS backgrounds or cut an object out of a photograph.

The correct IMGKit option

IMGKit is a Python wrapper around the wkhtmltoimage command-line utility. IMGKit forwards option names without the leading double hyphens. A valueless switch can be represented with an empty string, None, or False. The most readable form is an empty string because it mirrors the command-line flag.

import imgkit

html = """
<!doctype html>
<html>
  <body>
    <div>Hello</div>
  </body>
</html>
"""

options = {
    "format": "png",
    "transparent": "",
}

imgkit.from_string(html, "out.png", options=options)

The generated out.png can contain an alpha channel. In wkhtmltoimage’s terminology, transparent means “Make the background transparent in pngs.”

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Equivalent flag values

IMGKit value Meaning When to use it
"transparent": "" Passes a valueless switch Recommended for clarity
"transparent": None Also passes the switch Useful when options are assembled programmatically
"transparent": False Also treated as a valueless switch by IMGKit Use only if your project already represents flags this way

Choose one representation and use it consistently. Do not add the leading --; IMGKit adds that when it builds the wkhtmltoimage command.

Why no-background produces an error

--no-background belongs to wkhtmltopdf’s page/PDF options, not to the image renderer’s transparency option. If you put "no-background": "" in IMGKit options, wkhtmltoimage may stop with an error such as Unknown long argument --no-background. That message means the binary does not recognize the option, not that your Python dictionary needs a different Boolean value.

Replace the key with exactly transparent. The option is implemented by wkhtmltoimage and is intended for PNG output (and SVG output in builds that support it).

Output format and CSS requirements

Use PNG or supported SVG

JPEG has no alpha channel, so it cannot preserve transparent pixels. Set "format": "png" and use a .png filename. If your installed wkhtmltoimage build supports SVG transparency, "format": "svg" is another possible target; verify that format with the binary you deploy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
options = {
    "format": "png",
    "transparent": None,
}
imgkit.from_string(html, "out.png", options=options)

Do not paint an opaque page behind the content

The flag makes the renderer’s default white canvas transparent. It does not override CSS. A rule such as body { background: white; }, a full-page wrapper with a solid background, or an element with its own colored background will still render that color. Remove or change those declarations while testing.

html = """
<html>
  <head>
    <style>
      html, body { margin: 0; padding: 0; background: transparent; }
      .badge { display: inline-block; padding: 12px 16px; color: #111; }
    </style>
  </head>
  <body>
    <div class="badge">Transparent canvas</div>
  </body>
</html>
"""

imgkit.from_string(
    html,
    "badge.png",
    options={"format": "png", "transparent": ""},
)

This is canvas transparency, not object segmentation. If a photograph or illustration itself contains a colored background, wkhtmltoimage will not identify and remove that background.

Set up IMGKit and the renderer

  1. Install IMGKit in the Python environment. Use the package manager and virtual environment convention used by your project.
  2. Install wkhtmltoimage. IMGKit is only a wrapper; the executable must be installed on the machine that runs the code.
  3. Check discoverability. Ensure wkhtmltoimage is on PATH, or provide its absolute path through IMGKit’s configuration object.
  4. Run a minimal PNG test. Start with plain HTML and no CSS background so renderer problems are separate from page styling problems.

Using an explicit binary path

When the executable is not on PATH, configure it explicitly. The exact path differs by operating system and installation method.

import imgkit

config = imgkit.config(wkhtmltoimage="/absolute/path/to/wkhtmltoimage")
options = {"format": "png", "transparent": ""}
imgkit.from_string("<div>Hello</div>", "out.png", options=options, config=config)

Keep the path in deployment configuration rather than hard-coding a workstation-specific location when the same application runs in containers, CI, and production.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

End-to-end example with a file

The following script renders an HTML string, writes a PNG, and fails loudly if IMGKit cannot invoke the binary.

from pathlib import Path
import imgkit

SOURCE = """
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <style>
    html, body { margin: 0; padding: 0; background: transparent; }
    .card { padding: 24px; font: 24px/1.3 Arial, sans-serif; color: #222; }
  </style>
</head>
<body>
  <div class="card">Hello from IMGKit</div>
</body>
</html>
"""

output = Path("out.png")
options = {
    "format": "png",
    "transparent": "",
}

try:
    imgkit.from_string(SOURCE, str(output), options=options)
except OSError as exc:
    raise SystemExit(
        "wkhtmltoimage could not be started. Install it, put it on PATH, "
        "or configure its binary path."
    ) from exc

if not output.exists() or output.stat().st_size == 0:
    raise SystemExit("The renderer returned no image")

print(f"Wrote {output} ({output.stat().st_size} bytes)")

Diagnose the same setting outside Python

Running wkhtmltoimage directly helps distinguish an IMGKit option problem from a renderer or installation problem. The command accepts an input HTML file and an output image file:

wkhtmltoimage --format png --transparent input.html out.png

If this direct command fails with an unknown option, inspect the installed binary and its version. If it succeeds but IMGKit fails, check the Python option key, binary path, and the arguments IMGKit is forwarding.

Or skip the browser setup

ScreenshotNeo provides a website screenshot API when you need a URL captured without maintaining a wkhtmltoimage installation. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a URL such as Stripe’s homepage, one request is enough:

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(`HTTP ${res.status}`);
const buffer = Buffer.from(await res.arrayBuffer());
require('fs').writeFileSync('shot.webp', buffer);

See the ScreenshotNeo API documentation for request options. If your goal is a clean webpage capture rather than rendering local HTML, this avoids browser-binary setup, removes common overlays before the shot, does not charge for failed or blocked pages, and lets an AI agent capture through MCP. Create a free ScreenshotNeo account to get 1,000 screenshots each month with no card.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting transparent PNGs

“Unknown long argument –no-background”

Cause: The image renderer does not define that option. Fix: Change the IMGKit key to transparent and keep the output format as PNG or supported SVG.

The file has a white rectangle

Cause: The page or a wrapper paints an opaque background, or the viewer displays transparency as white. Fix: Remove background and background-color declarations from html, body, and full-page containers while testing. Open the file in an image viewer that shows alpha with a checkerboard; the checkerboard is viewer UI, not pixels in the PNG.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

IMGKit cannot start wkhtmltoimage

Cause: The executable is missing, not executable, or absent from PATH. Fix: Install the wkhtmltoimage binary, verify its location, or pass that location through imgkit.config(wkhtmltoimage=...). In a service, also check the user and container permissions.

The PNG has speckles or noisy pixels

Cause: Transparent output quality can vary between wkhtmltoimage builds; the project issue tracker contains reports of noise pixels. Fix: Record the binary version, test the same HTML with a different supported build, and pin the renderer version that produces acceptable output before deploying.

Transparency works in a small test but not in the real page

Cause: The production document includes a CSS background, an embedded asset with its own background, or layout that extends the painted area. Fix: Reduce the page to the smallest failing element, inspect computed styles, and reintroduce styles and assets one at a time. Remember that transparent does not perform automatic background removal.

Choosing the right approach

Need Best fit Important limitation
Render your own HTML string or local file in Python IMGKit with wkhtmltoimage and transparent You must install and maintain the renderer binary
Preserve a transparent canvas PNG (or supported SVG) JPEG cannot carry alpha transparency
Remove arbitrary colored pixels or isolate a subject A dedicated image-editing or segmentation workflow wkhtmltoimage transparency is not object removal
Capture a live website URL with overlays cleaned up ScreenshotNeo It is a URL screenshot service rather than a local IMGKit renderer

Deployment checklist

  • Use the exact option key transparent, without leading hyphens.
  • Set format to png when alpha is required.
  • Use a PNG filename and verify the output is non-empty.
  • Remove opaque CSS backgrounds from the page and wrappers.
  • Confirm wkhtmltoimage is installed, executable, and the expected binary is being used.
  • Pin and test the renderer build if transparent output shows noise.
  • Inspect the file with an alpha-aware image viewer.

The Bottom Line

For Python IMGKit, the no-background equivalent is transparent, not no-background. Render to PNG, avoid opaque CSS backgrounds, and verify the wkhtmltoimage build when output quality varies.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.