ImageViewer

An image you can zoom, pan, rotate and download, with keyboard and touch support.

Status: beta. Category: Viewers.

import { ImageViewer } from '@glyphui/viewers/media'

Exports: ImageViewer, imageViewerStyles.

Notes

  • No extra packages needed.
  • Zoom with the buttons, ⌘ or Ctrl + scroll, a trackpad pinch or two fingers. Plain scrolling still scrolls the page.
  • Keyboard: + and − zoom, 0 fits, 1 shows actual size, R rotates, arrow keys pan.

ImageViewer props

PropTypeDefaultDescription
alt (required)stringAlternative text. Required for meaningful images.
source (required)ViewerSourceThe image: a URL, a File/Blob, or bytes.
borderedbooleanDraw the viewer as a bordered card. Default true.
classNamestring
downloadablebooleanShow a download button. Default true.
heightstring | numberHeight of the viewer. Default 420.
maxZoomnumber
minZoomnumberZoom limits, as a scale of the natural size. Default 0.05–16.

Example: Zoom and pan

Double-click to zoom in, drag to pan.

import { ImageViewer } from '@glyphui/viewers/media'
import { fixture } from '../../../lib/fixtures'

export default function Example() {
  return (
    <ImageViewer
      source={fixture('aurora.jpg')}
      alt="A blue-to-green gradient with a faint grid"
      height={400}
      className="w-full"
    />
  )
}

Live page: https://glyphui.xyz/components/image-viewer