Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsTo save a PNG with wkhtmltoimage from Free Pascal or Lazarus, use the documented image.h C binding lifecycle: initialize the library, create global settings, set fmt to png, set in and either out or an empty out value, create a converter, run it, retrieve output if you selected the in-memory route, then destroy the converter and deinitialize the library. A filename ending in .png does not select PNG by itself.
The old “Could not save image” report associated with Free Pascal/Lazarus is version-specific evidence from 2017, not proof of a current general defect. Record your exact wkhtmltoimage build and settings before attempting a workaround.
What the binding does
The upstream documentation describes image.h as a “fairly high level and stable pure c binding to wkhtmltoimage.” It is the intended interface for applications that need to render a URL or local input into an image. Pascal code should call the same native functions and preserve their calling conventions and parameter types.
Choose a PNG output route
Write directly to a file
Set fmt to png, set in to the URL or input path, and set out to the destination path. The converter writes the result there when conversion succeeds. Use this route when the next stage of your program can consume a normal file.
#1 Best Overall
- CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
- WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
- A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
Return PNG bytes to your program
Set out to an empty value. After conversion, call wkhtmltoimage_get_output to obtain a pointer and a byte length, then write exactly that many bytes to a file, stream, database field or HTTP response. Do not treat the pointer as a null-terminated Pascal string; PNG data is binary and can contain zero bytes.
Send output to standard output
An out value of - directs output to stdout. This is useful when another process owns the file or stream, but it requires you to manage stdout separately from diagnostic logging.
Documented conversion lifecycle
- Call the library initialization function before creating any settings or converter.
- Create a global settings object.
- Set the input, format and destination settings. For PNG, use
fmt = png. - Create a converter from the settings object. The converter consumes that settings object, so do not reuse or free it as though it remained independent.
- Optionally attach progress, phase and warning/error callbacks.
- Call the conversion function and test its Boolean result.
- For buffer output, call
wkhtmltoimage_get_outputand copy the returned byte count. - Destroy the converter, then deinitialize the library when your process is finished with wkhtmltoimage.
Settings that control PNG output
| Setting | Value or meaning |
|---|---|
fmt |
png for PNG output. The documented formats also include an empty value, jpg, bmp and svg. |
in |
Input URL or local path. |
out |
File path, - for stdout, or an empty value for an internal output buffer. |
transparent |
Enables a transparent replacement for a white background when output is PNG or SVG. The page itself must also be styled so that transparency is meaningful. |
Set the format explicitly even when the destination has a .png extension. The extension is only a filename convention; fmt is the conversion setting.
Pascal binding design
No official Pascal binding or verified Free Pascal byte-copy implementation is supplied with the library documentation. Treat the following as a binding pattern, not a drop-in declaration for every package. Compare every declaration with the headers and import library used by your build, especially the calling convention, integer widths, Boolean representation and string-pointer types.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11type
TNativeBool = LongBool;
TSettings = Pointer;
TConverter = Pointer;
function wkhtmltoimage_init(useGraphics: TNativeBool): TNativeBool; cdecl; external 'libwkhtmltox';
function wkhtmltoimage_deinit: TNativeBool; cdecl; external 'libwkhtmltox';
function wkhtmltoimage_create_global_settings: TSettings; cdecl; external 'libwkhtmltox';
function wkhtmltoimage_set_global_setting(settings: TSettings; name, value: PAnsiChar): TNativeBool; cdecl; external 'libwkhtmltox';
function wkhtmltoimage_create_converter(settings: TSettings): TConverter; cdecl; external 'libwkhtmltox';
function wkhtmltoimage_convert(converter: TConverter): TNativeBool; cdecl; external 'libwkhtmltox';
function wkhtmltoimage_get_output(converter: TConverter; output: PPointer): Cardinal; cdecl; external 'libwkhtmltox';
procedure wkhtmltoimage_destroy_converter(converter: TConverter); cdecl; external 'libwkhtmltox';
Names, exported symbols and the exact output-length type can differ between packages. Use the declarations generated or documented for your particular wkhtmltox build rather than assuming this illustrative signature is ABI-compatible.
Rank #2
- CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
- SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
File-output example in Free Pascal
The following shows the order of operations. Replace declarations with those matching your native headers and add the callback declarations required by your package.
uses SysUtils;
var
gs: TSettings;
conv: TConverter;
ok: TNativeBool;
begin
if wkhtmltoimage_init(False) = 0 then
raise Exception.Create('wkhtmltoimage initialization failed');
try
gs := wkhtmltoimage_create_global_settings();
if gs = nil then
raise Exception.Create('Could not create global settings');
if wkhtmltoimage_set_global_setting(gs, 'in',
PAnsiChar(AnsiString('https://example.com'))) = 0 then
raise Exception.Create('Could not set input');
if wkhtmltoimage_set_global_setting(gs, 'fmt',
PAnsiChar(AnsiString('png'))) = 0 then
raise Exception.Create('Could not set PNG format');
if wkhtmltoimage_set_global_setting(gs, 'out',
PAnsiChar(AnsiString('page.png'))) = 0 then
raise Exception.Create('Could not set output path');
if wkhtmltoimage_set_global_setting(gs, 'transparent',
PAnsiChar(AnsiString('true'))) = 0 then
raise Exception.Create('Could not set transparency');
conv := wkhtmltoimage_create_converter(gs);
if conv = nil then
raise Exception.Create('Could not create converter');
try
ok := wkhtmltoimage_convert(conv);
if ok = 0 then
raise Exception.Create('Conversion failed');
finally
wkhtmltoimage_destroy_converter(conv);
end;
finally
wkhtmltoimage_deinit();
end;
end.
Keep the strings passed to the native call valid for the duration of that call. If your binding stores pointers internally, follow its documented ownership rules rather than passing temporary memory that is released too early.
Reading the returned PNG buffer
For memory output, set out to an empty string and obtain the returned pointer only after a successful conversion. Copy the exact returned length before destroying the converter.
var
data: Pointer;
byteCount: Cardinal;
stream: TFileStream;
begin
{ Configure in and fmt=png; configure out as an empty value. }
if wkhtmltoimage_convert(conv) = 0 then
raise Exception.Create('Conversion failed');
data := nil;
byteCount := wkhtmltoimage_get_output(conv, @data);
if (data = nil) or (byteCount = 0) then
raise Exception.Create('No PNG bytes returned');
stream := TFileStream.Create('page.png', fmCreate);
try
stream.WriteBuffer(data^, byteCount);
finally
stream.Free;
end;
end;
The pointer belongs to the converter’s output. Finish copying it before wkhtmltoimage_destroy_converter. Do not call string conversion routines, append a terminator, or use a character-count function.
Transparent website images
The transparent setting is documented for PNG and SVG. It does not automatically remove a colored page background, an opaque element, or an image’s own background. Set the page’s CSS background to transparent where appropriate, and test the result against both light and dark viewers.
Rank #3
- Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
- Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
- Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
- In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
- Ultra-thin bezels: Maximize your viewing experience with thin bezels.
Callbacks and diagnostics
The upstream C example attaches callbacks for progress, phases and warnings or errors, checks the conversion result, and obtains the HTTP error code. A Pascal application should expose equivalent callbacks if its binding supports them. Log the callback text, HTTP status, input URL, all global settings and the native library version. This makes a failure reproducible instead of reducing it to a generic “save” error.
Understanding “Could not save image”
A Stack Overflow question posted by user thz on July 14, 2017 reported that JPEG and SVG worked while PNG produced the callback message “Could not save image.” An answer posted July 16 suggested a problem in version 0.12.4 and said 0.12.3 worked. That exchange is an old anecdote, not a current compatibility matrix or a verified fix for modern packages.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Separate two possibilities:
- Configuration: the format was not set to
png, the destination is unwritable, or buffer bytes are being mishandled. - Runtime/build behavior: a particular wkhtmltox binary, Qt build, operating system or package has a PNG-specific defect.
Test direct file output first. If that succeeds, compare it with the buffer path; the problem may be in Pascal’s memory copy rather than the renderer. If direct output fails, reproduce with the smallest URL and no optional settings, then add transparency and other options one at a time.
Troubleshooting checklist
The converter is nil
Initialization may not have run, the native library may not have loaded, or the settings object was invalid. Check dynamic-library search paths, bitness (32-bit versus 64-bit), calling convention and the return value of every creation function.
Conversion returns false
Capture callback diagnostics and the HTTP error code. Verify that the input URL is reachable by the rendering process, local paths use the syntax expected by your build, and required network resources are available.
Rank #4
- CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
- SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
- MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
- KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
- INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
“Could not save image” with file output
Confirm that the parent directory exists and is writable by the process, that the path is not a directory, and that another process is not locking the file. Then record the exact wkhtmltox version and platform. The 0.12.3/0.12.4 report should not be generalized to your installation.
PNG file is empty or corrupted from a buffer
Check the returned pointer and length, write exactly the length as bytes, and copy before destroying the converter. A string-based write commonly truncates binary data at the first zero byte.
Transparency appears white
Confirm transparent is set to true, the requested format is PNG, and the rendered document does not paint an opaque background. Inspect the file with an image viewer that shows transparency.
JPEG works but PNG does not
That pattern does not prove your Pascal declarations are correct or incorrect. Recheck fmt, test a direct destination, try a minimal input, and compare the exact native build. There is no established current universal workaround for the historical report.
Performance, reliability and cleanup
Reuse no settings or converter object unless your binding explicitly documents that behavior. A converter consumes its settings object, and each conversion should have a clear ownership boundary. Keep callback logging lightweight, set an application-level timeout around the conversion, and clean up in a finally block even when conversion fails. For batches, isolate failures per URL so one bad page does not prevent later jobs from being attempted.
Best Value
- 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
- 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
- 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
PNG is lossless and can be substantially larger than JPEG; choose it when transparency or lossless pixels matter. The supplied documentation does not establish a general speed, memory or failure-rate figure, so measure your own pages and native build.
Or skip the browser setup
If your goal is a clean website image rather than maintaining a wkhtmltoimage runtime, ScreenshotNeo provides a single HTTP request for PNG, JPEG, WebP or PDF. It accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status.
cURL (see the ScreenshotNeo documentation):
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)
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}`);
ScreenshotNeo also exposes an MCP server with take_screenshot, get_page_info and capture_pdf for Claude, Cursor and other MCP clients. Every feature is on every plan; 1,000 shots per month are free without a card, and paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.
Frequently Asked Questions
Does a .png filename force wkhtmltoimage to emit PNG?
No. Set the global fmt setting to png; the filename extension is not a substitute.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →When can I safely free the converter?
After conversion and, for buffer output, after copying all bytes returned by wkhtmltoimage_get_output.
Is version 0.12.3 a guaranteed fix for PNG failures?
No. It was suggested in a July 2017 report and is not a current compatibility guarantee.
Quick Recap
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.

