Skip to Content
OpenPreview

Images

Show PNG, JPEG, GIF, WebP, AVIF, BMP, ICO, SVG, TIFF, HEIC and EMF/WMF images in React, with zoom, rotation and multi-page TIFF scans.

Live: photo.jpg rendered by the library in this page.Open in the playground
FormatHow it is drawn
PNG, JPEG, GIF, WebP, AVIF, BMP, ICOThe browser's own decoders.
SVGAs an image, so scripts inside the file never run.
TIFFOur own decoder, in every browser.
HEIC, HEIFSafari natively. Elsewhere our HEIF reader passes the tiles to the browser's HEVC decoder (WebCodecs), available in Chrome and Edge on systems with HEVC support; other browsers show a clear message.
EMF, WMFOur own metafile interpreter, converting to SVG.

TIFF

Strips and tiles; no compression, LZW, Deflate, PackBits, CCITT G3 and G4 fax and JPEG; predictors; 1 to 16 bits per sample; palette, CMYK, CIE L*a*b* and alpha; planar data; BigTIFF and orientation. Multi-page files show as pages with thumbnails, and print at their scanned size when the file states a resolution.

Live: scan.tiff rendered by the library in this page.Open in the playground

EMF and WMF

Shapes, paths, pens and brushes (hatches and patterns too), text with per-character spacing, Symbol-font maths, clipping, world transforms, gradients, bitmaps, and WMF embedded in EMF. The same interpreter draws metafile pictures inside Word, Excel and PowerPoint files. Pictures stored only as EMF+ (GDI+) are not drawn yet.

Controller

StateFor imagesFor TIFF
page, pageCountNo pages (pageCount 0).'page', the page in view and the number of pages.
zoom, scaleEvery zoom, fit modes included. 'actual' is one image pixel per CSS pixel.Same.
rotation0, 90, 180 or 270.Same, for every page.
thumbnailsNone.One per page.
outlineNone.None.
searchNot searchable (can.search false).Not searchable.
canzoom, fit, rotate, print, download.zoom, fit, rotate, print, download, sidebar.
Live: useDocViewer on scan.tiff. Press a command and watch the state change.

Headless

An image viewer with a zoom slider, fit and actual size, rotation, and page thumbnails that appear only for multi-page files:

examples/headless/images.tsx
'use client';
// An image viewer: zoom slider, fit and actual size, rotation. Multi-page TIFF scans also get
// page navigation and thumbnails; other images have pageCount 0 and no thumbnails.
import { DocumentSurface, Thumbnail, useDocViewer, useThumbnails, type DocSource } from '@openpreview/react';
import '@openpreview/react/styles.css';

export default function ImageViewer({ source }: { source: DocSource }) {
  const viewer = useDocViewer({ source, defaultZoom: 'fit-page' });
  const pages = useThumbnails(viewer);

  return (
    <div className="flex h-full flex-col text-sm">
      <header className="flex flex-wrap items-center gap-3 border-b p-2">
        <input
          type="range"
          aria-label="Zoom"
          min={0.1}
          max={4}
          step={0.05}
          value={viewer.scale}
          onChange={(e) => viewer.setZoom(Number(e.target.value))}
        />
        <span>{Math.round(viewer.scale * 100)}%</span>
        <button onClick={() => viewer.setZoom('fit-page')}>Fit</button>
        <button onClick={() => viewer.setZoom('actual')}>100%</button>
        {viewer.can.rotate && <button onClick={viewer.rotate}>Rotate</button>}
        {viewer.pageCount > 1 && (
          <span>
            Page {viewer.page} of {viewer.pageCount}
          </span>
        )}
        <button className="ml-auto" onClick={viewer.download}>Download</button>
      </header>
      <div className="flex min-h-0 flex-1">
        {pages && pages.count > 1 && (
          <nav className="w-32 shrink-0 overflow-y-auto border-r p-2">
            {Array.from({ length: pages.count }, (_, i) => (
              <button key={i} className="mb-2 block" onClick={() => viewer.goTo(i + 1)}>
                <Thumbnail viewer={viewer} index={i} width={100} />
              </button>
            ))}
          </nav>
        )}
        <DocumentSurface viewer={viewer} className="min-w-0 flex-1" />
      </div>
    </div>
  );
}
Live: the example above, built only with the public hooks, running on scan.tiff.

On this page