Url2Image 1.0.0

dotnet add package Url2Image --version 1.0.0
                    
NuGet\Install-Package Url2Image -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Url2Image" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Url2Image" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Url2Image" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Url2Image --version 1.0.0
                    
#r "nuget: Url2Image, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Url2Image@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Url2Image&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Url2Image&version=1.0.0
                    
Install as a Cake Tool

Url2Image = URL → Full‑page PNG/JPEG for .NET

Tiny service that turns any URL into a full‑page screenshot using [Microsoft.Playwright]. Works on Windows, Linux, macOS. Default PNG, optional JPEG with quality. Returns a Stream with helpers to save to disk.

NuGet License: MIT .NET

Install

dotnet add package Url2Image

Or install with automatic Playwright browser setup:

dotnet add package Url2Image
# Add to your project file: <InstallPlaywright>true</InstallPlaywright>

Heads‑up about Playwright browsers

Playwright requires browser binaries. This package can auto‑install them at app startup (recommended in containers) or you can install them once for your app using the Playwright script. First run will hang for 1-5 minutes while downloading ~200MB of browser binaries. See Setup below.

Quick start (ASP.NET Core minimal API)

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddUrl2Image(o => o.AutoInstallBrowsersOnStartup = true); // optional

var app = builder.Build();

app.MapGet("/shot", async (string url, IUrlScreenshotService svc) =>
{
    await using var png = await svc.CaptureAsync(url);
    return Results.File(png, "image/png");
});

await app.RunAsync();

API

Task<Stream> CaptureAsync(string url, ScreenshotOptions? options = null, CancellationToken ct = default);
Task SaveToFileAsync(string url, string filePath, ScreenshotOptions? options = null, CancellationToken ct = default);
Task<byte[]> CaptureBytesAsync(string url, ScreenshotOptions? options = null, CancellationToken ct = default);

ScreenshotOptions

  • Format: Png (default) or Jpeg
  • JpegQuality: 1–100 (only for JPEG; default 80)
  • ViewportWidth: default 1400
  • ViewportHeight: default 1080 (full‑page capture ignores height for final image)
  • DeviceScaleFactor: default 1.0 (use >1 for sharper text)
  • NavigationTimeout: default 30s
  • WaitUntil: DomContentLoaded (default) | Load | NetworkIdle
  • FullPage: default true
  • DisableAnimations: default true
  • UserAgent: optional string

Setup

You have two options. Pick one:

A) Auto‑install on app startup (recommended in containers/CI)

builder.Services.AddUrl2Image(o => o.AutoInstallBrowsersOnStartup = true);

This triggers a best‑effort Playwright install for Chromium. First run will hang for 1-5 minutes while downloading ~200MB of browser binaries. Requires network/file system access.

B) Install browsers once per project (no code)

Run after adding the NuGet (replace net9.0 with your TFM if different):

pwsh bin/Debug/net9.0/playwright.ps1 install

Linux notes

On Debian/Ubuntu‑based hosts you may also need OS packages (fonts, NSS, etc.). You can install both browsers and OS deps with:

pwsh bin/Debug/net9.0/playwright.ps1 install --with-deps

In Docker, base from mcr.microsoft.com/dotnet/aspnet:9.0-jammy and consider:

FROM mcr.microsoft.com/dotnet/aspnet:9.0-jammy
WORKDIR /app
COPY ./publish .
# Install Playwright browsers + deps into the container layer
RUN pwsh -NoProfile ./playwright.ps1 install --with-deps chromium || true
ENTRYPOINT ["dotnet","YourApp.dll"]

Example endpoint with JPEG

app.MapGet("/shot.jpg", async (string url, IUrlScreenshotService svc) =>
{
    var opts = new ScreenshotOptions(Format: ImageFormat.Jpeg, JpegQuality: 85);
    var jpg = await svc.CaptureBytesAsync(url, opts);
    return Results.File(jpg, "image/jpeg");
});

Gotchas / Tips

  • First run delay → Auto-installing browsers takes 1-5 minutes and ~200MB. Use manual install for faster startup.
  • Huge pages → Full‑page PNGs can be large. Prefer JPEG for very long pages or downscale via DeviceScaleFactor.
  • Flaky pages → Try WaitUntil = NetworkIdle or increase NavigationTimeout.
  • Security → Validate/whitelist input URLs if exposing this as a public API.
  • Headful vs headless → This library uses headless by default.

License

  • Library: MIT
  • Dependency: Microsoft.PlaywrightApache‑2.0
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 195 9/15/2025

Initial release with full-page screenshot capture using Playwright.