npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

openseadragon-capture

v1.1.0

Published

Capture high-quality screenshots from OpenSeadragon viewers with optional overlay layers.

Downloads

12

Readme

openseadragon-capture

codecov npm version License: MIT Build Status Downloads

Capture high-quality screenshots from OpenSeadragon viewers with optional overlay layers.

Installation

npm install openseadragon-capture

Usage

import OpenSeadragon from 'openseadragon';
import { createScreenshot } from 'openseadragon-capture';

// Initialize OpenSeadragon viewer with CORS support
const viewer = OpenSeadragon({
  id: 'viewer',
  tileSources: 'path/to/your/image.dzi',
  crossOriginPolicy: 'Anonymous' // Required for screenshot export
});

// Wait for viewer to open
viewer.addHandler('open', async () => {
  // Create screenshot instance
  const screenshot = createScreenshot(viewer);

  // Capture as Blob (recommended - memory efficient)
  const blob = await screenshot.toBlob({
    format: 'png',
    quality: 0.9,
    scale: 2
  });

  // Or capture as data URL
  const dataUrl = await screenshot.capture({
    format: 'png',
    quality: 0.9,
    overlays: [overlayCanvas]
  });

  // Or download directly
  await screenshot.download('screenshot.png', {
    overlays: [overlayCanvas]
  });
});

API

createScreenshot(viewer: OpenSeadragon.Viewer): OpenSeadragonScreenshot

Creates a screenshot instance for the given viewer.

toBlob(options?: ScreenshotOptions): Promise<Blob>

Captures the viewer as a Blob. Recommended for memory efficiency.

Throws: Error if viewer is not open or canvas is unavailable.

capture(options?: ScreenshotOptions): Promise<string>

Captures the viewer as a data URL.

Throws: Error if viewer is not open or canvas is unavailable.

download(filename: string, options?: ScreenshotOptions): Promise<void>

Captures and downloads the screenshot with the specified filename.

ScreenshotOptions

export type ScreenshotFormat = 'png' | 'jpeg' | 'webp';

interface ScreenshotOptions {
  /** Output image format. @default 'png' */
  format?: ScreenshotFormat;
  
  /** Image quality (0-1). @default 0.9 */
  quality?: number;
  
  /** 
   * Upscaling factor applied via canvas interpolation.
   * Does NOT fetch higher-resolution tiles.
   * @default 1 
   */
  scale?: number;
  
  /** 
   * Overlay canvases to composite.
   * Must already be in viewer pixel space with transforms applied.
   */
  overlays?: HTMLCanvasElement[];
  
  /** 
   * If true, temporarily fits entire image to viewport before capture.
   * Causes momentary viewport change.
   * @default true 
   */
  fitImageToViewport?: boolean;
  
  /** 
   * Index of the tiled image to capture (for multi-image viewers).
   * @default 0 
   */
  imageIndex?: number;
}

Important Limitations

⚠️ CORS Requirement: Images must be served with CORS headers. Set crossOriginPolicy: 'Anonymous' in viewer config. CORS errors will cause capture to fail.

⚠️ Scale Behavior: The scale parameter upscales via canvas interpolation. It does NOT fetch higher-resolution tiles. For true high-resolution exports, tiles must be loaded at the target resolution.

⚠️ Viewport Changes: fitImageToViewport: true temporarily changes the viewport to fit the entire image, which may cause visual flicker.

⚠️ Overlay Requirements: Overlay canvases must already be in viewer pixel space with transforms applied. Overlays with mismatched dimensions will be stretched.

⚠️ Timing: Capture waits for tiles to load using heuristic-based timing. May fail if tiles load slowly.

⚠️ Memory: Large scale factors can create very large canvases (warning shown if exceeding 16MP).

Production Considerations

  • Always handle promise rejections (CORS errors are common)
  • Use toBlob() instead of capture() for better memory management
  • Wait for viewer 'open' event before capturing
  • Test with your specific tile sources and CORS configuration
  • Validate overlay canvas dimensions match viewer canvas
  • Be cautious with large scale factors to avoid memory issues

License

MIT