ScreenshotNeo

BlogHow-to

How to Fix ApiFlash Screenshots with Incorrect Page Dimensions

Diagnose ApiFlash screenshot size mismatches by checking viewport dimensions, full-page mode, scaling, crops, elements, caching, and delayed rendering.

By the ScreenshotNeo team4 October 20267 min read

To fix an ApiFlash screenshot with incorrect dimensions, first compare the returned image’s pixel size with the request’s width, height, full_page, and scale_factor. For a fixed viewport, set both dimensions and keep full_page=false. With full_page=true, ApiFlash captures the page’s full rendered height and ignores height. Then check for a crop or element target, stale cache, and content that rendered late.

This guide uses ApiFlash’s documented API behavior. Its defaults and limits are product specifications and can change; check the current API documentation if a request behaves differently.

1. Identify which dimension is wrong

Record the exact request parameters and inspect the downloaded file’s pixel dimensions. Separate these three questions:

  • Is the output bitmap the wrong pixel width or height? Check viewport dimensions, full-page mode, scale factor, crop, and element capture.
  • Is the output the right size, but content is clipped or missing? Check the selected capture area and whether the page had finished rendering.
  • Is the layout different despite the expected pixel size? Check responsive breakpoints, fonts, and rendering environment.

ApiFlash documents a default viewport of 1920 by 1080 pixels. The width and height parameters describe the browser viewport, not necessarily the final bitmap dimensions when a scale factor, full-page capture, or crop changes the output.

2. Choose viewport or full-page capture

A viewport capture has a fixed browser width and height. Set both explicitly and use full_page=false (the documented default). A full-page capture uses the viewport width but extends the screenshot to the rendered page height; ApiFlash ignores height in that mode.

Desired output Request setup What to expect
Fixed viewport width, height, full_page=false Capture is constrained to the viewport.
Entire page width, full_page=true Image height follows the rendered page; height is ignored.

Example: if the request sets width=1365, height=768, and full_page=true, do not expect a 768-pixel-tall result. Turn full-page mode off to request a fixed 1365-by-768 viewport.

3. Check scaling, crop, and element selection

Scale factor

scale_factor accepts 1 or 2. A factor of 2 creates a higher-definition image with more pixels and a larger file. If the bitmap is twice the expected viewport dimensions, check whether the request uses scale_factor=2 before changing the viewport or page CSS.

Crop

The crop parameter selects a rectangle in left,top,width,height form. Remove it while diagnosing a mismatch, or verify that the rectangle describes the intended region. A crop intentionally returns only that selected part of the page.

Element capture

The element parameter takes a URL-encoded CSS selector and targets the first matching element. Confirm the selector matches the intended element, and remove the parameter to test a normal page capture. ApiFlash documents that element is ignored when full_page=true; use a non-full-page request when you specifically want an element capture.

4. Send a controlled request

Start with a known viewport request, then add options one at a time. ApiFlash accepts GET query parameters or POST form data. Include the protocol in the target URL. The following GET examples save the returned image so its actual pixel dimensions can be inspected.

cURL

curl -G "https://api.apiflash.com/v1/urltoimage" \
  --data-urlencode "access_key=YOUR_API_KEY" \
  --data-urlencode "url=https://example.com" \
  --data-urlencode "width=1365" \
  --data-urlencode "height=768" \
  --data-urlencode "full_page=false" \
  --data-urlencode "scale_factor=1" \
  -o screenshot.png

Python

import requests

params = {
    "access_key": "YOUR_API_KEY",
    "url": "https://example.com",
    "width": 1365,
    "height": 768,
    "full_page": "false",
    "scale_factor": 1,
}
response = requests.get(
    "https://api.apiflash.com/v1/urltoimage",
    params=params,
    timeout=90,
)
response.raise_for_status()
with open("screenshot.png", "wb") as image:
    image.write(response.content)
print("Saved screenshot.png", len(response.content), "bytes")

Node.js

const params = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://example.com',
  width: '1365',
  height: '768',
  full_page: 'false',
  scale_factor: '1',
});

const response = await fetch(
  `https://api.apiflash.com/v1/urltoimage?${params}`
);
if (!response.ok) {
  throw new Error(`ApiFlash returned HTTP ${response.status}`);
}
const bytes = Buffer.from(await response.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('screenshot.png', bytes));
console.log(`Saved screenshot.png (${bytes.length} bytes)`);

For a full-page test, change full_page to true and do not use height to predict the result height. For an element test, remove full-page mode and add the documented element selector parameter. The code above deliberately establishes a baseline before adding those constraints.

5. Wait for the right content and bypass stale results

ApiFlash says its normal behavior waits for network idle. If the page builds content after that point, use wait_for to wait for a specific element, or add an appropriate delay. The documented delay range is 0 to 10 seconds. Prefer waiting for a meaningful selector when possible; a fixed delay can be too short on a slow run and unnecessarily long on a fast one.

Repeated identical requests may return a cached screenshot. Set fresh=true when you need to bypass the cached result and capture the current page. ApiFlash documents a default screenshot cache duration of 86,400 seconds. Do not interpret a stale screenshot as a viewport problem until you have checked freshness.

6. Validate limits and the rendered layout

ApiFlash documents an individual maximum of 16,350 pixels for width or height, and a maximum width × height of 33,177,600 pixels. Keep requested viewport dimensions within those limits. A request can be rejected even when each side is individually within range if their product exceeds the maximum.

When dimensions are numerically correct but the page looks different, check responsive breakpoints and font loading. ApiFlash captures with Chrome on Linux, so system fonts can differ from those on a developer’s machine. Its FAQ recommends serving fonts with the site rather than relying on operating-system fonts. Use web-hosted or self-hosted fonts and wait for the page’s font-dependent content to render before capture.

7. Troubleshooting checklist

Symptom Likely cause Fix
Height does not match the requested value full_page=true Set full_page=false for a fixed viewport. Full-page mode ignores height.
Both bitmap dimensions are larger than expected scale_factor=2 Use factor 1 for the baseline, or account for the higher pixel density when comparing bitmap pixels with viewport CSS pixels.
Only part of the page appears crop or element narrows the capture Remove the option to test a normal capture; then verify the crop rectangle or first matching selector.
Screenshot shows old content Cached response Set fresh=true to bypass the cached result.
Expected section is blank or incomplete Content rendered after the default network-idle wait Use wait_for for a selector or a suitable delay between 0 and 10 seconds.
Layout differs while pixel dimensions match Different font availability or rendering environment Serve fonts with the site and check the responsive layout in Chrome on Linux.
HTTP 400 Invalid parameters or an uncapturable target URL Check parameter values, URL protocol, selector and crop syntax, and dimension limits.
HTTP 403 The plan does not support a requested feature Check whether the requested feature is available on the current plan.
HTTP 429 Too many requests Reduce request rate and retry according to the application’s backoff policy.

8. Reliability, performance, and cost considerations

Large viewport areas and a scale factor of 2 produce more image pixels; factor 2 also produces a larger file. Request only the dimensions and capture area needed by the downstream use. Full-page captures can be substantially taller than a viewport, so validate the resulting file rather than treating requested viewport height as an output guarantee.

For repeatable captures, make the request explicit about dimensions and mode, host the fonts the page needs, wait for a stable selector when content is asynchronous, and bypass cache when freshness matters. Treat 400, 403, and 429 responses differently: correct invalid input, review feature access, or reduce request pressure, respectively. The dossier does not establish ApiFlash prices or service-level guarantees, so check its current product pages for those details rather than assuming a rate or reliability figure.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. Its one-call API returns an image or PDF, and its parameter names support the ones other screenshot APIs use, which can make switching straightforward. See the ScreenshotNeo API documentation.

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

ScreenshotNeo removes cookie banners, popups, and chat widgets before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000.

Sign up free for 1,000 screenshots a month, no card required.

FAQ

Does height control the final image height?

It controls the browser viewport height. In full-page mode, ApiFlash ignores it and captures the rendered page height.

Why is my image twice as large as the viewport?

Check whether scale_factor=2 is enabled. It creates a higher-definition output with more pixels.

Why does the same request keep returning the same screenshot?

Identical calls may use a cached result. Set fresh=true when you need a new capture.

Can an element capture be combined with full-page mode?

ApiFlash documents that the element option is ignored when full_page=true. Turn full-page mode off to capture the selected element.

Sources