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

@temilayodev/react-element-capture

v1.1.0

Published

A React component for capturing and downloading HTML elements as images in multiple formats (PNG, JPEG, WebP).

Downloads

15

Readme

React Element Capture

A React component for capturing and downloading HTML elements as images in multiple formats (PNG, JPEG, WebP).

Installation

npm install @temilayodev/react-element-capture
yarn add @temilayodev/react-element-capture

Usage

Basic Usage (PNG Download)

import React from 'react';
import { PNGDownloadLink } from '@temilayodev/react-element-capture';

function App() {
  const contentToDownload = (
    <div style={{ padding: '20px', backgroundColor: 'white' }}>
      <h1>This will be downloaded as PNG</h1>
      <p>Some content here...</p>
    </div>
  );

  return (
    <div>
      <PNGDownloadLink 
        document={contentToDownload}
        fileName="my-image.png"
      >
        <button>Download as PNG</button>
      </PNGDownloadLink>
    </div>
  );
}

Multiple Format Support

import React from 'react';
import { ImageDownloadLink } from '@temilayodev/react-element-capture';

function App() {
  const contentToDownload = (
    <div style={{ padding: '20px', backgroundColor: 'white' }}>
      <h1>Download in any format</h1>
      <p>Some content here...</p>
    </div>
  );

  return (
    <div>
      {/* PNG (default) */}
      <ImageDownloadLink document={contentToDownload}>
        <button>Download PNG</button>
      </ImageDownloadLink>

      {/* JPEG with quality control */}
      <ImageDownloadLink 
        document={contentToDownload}
        quality={0.8}
        fileName="my-image.jpg"
      >
        <button>Download JPEG</button>
      </ImageDownloadLink>

      {/* WebP format */}
      <ImageDownloadLink 
        document={contentToDownload}
        quality={0.9}
        fileName="my-image.webp"
      >
        <button>Download WebP</button>
      </ImageDownloadLink>
    </div>
  );
}

Advanced Usage (Download + Share)

import React from 'react';
import { ImageDownloadLink } from '@temilayodev/react-element-capture';

function App() {
  const contentToDownload = (
    <div style={{ padding: '20px', backgroundColor: 'white' }}>
      <h1>This will be downloaded as image</h1>
      <p>Some content here...</p>
    </div>
  );

  return (
    <div>
      <ImageDownloadLink 
        document={contentToDownload}
        quality={0.9}
        fileName="my-image.jpg"
      >
        {({ download, share }) => (
          <div>
            <button onClick={download}>📥 Download JPEG</button>
            <button onClick={share}>🔗 Share JPEG</button>
          </div>
        )}
      </ImageDownloadLink>
    </div>
  );
}

Components

ImageDownloadLink (Recommended)

The main component with full format support (.png, .jpg, .jpeg, .webp).

PNGDownloadLink

Alias for ImageDownloadLink - supports all the same formats and features. Named for backward compatibility but works identically to ImageDownloadLink.

Props

| Prop | Type | Required | Description | |------|------|----------|-------------| | document | ReactNode | Yes | The React element/component to capture as image | | fileName | string | No | Name of the downloaded file with extension (default: 'image.png'). Format is derived from extension. | | quality | number | No | Image quality for lossy formats (0-1, default: 0.92, ignored for PNG) | | children | ReactNode | Function | Yes | The trigger element(s) or render function for custom UI | | scale | number | No | Canvas scale factor (default: 2) | | backgroundColor | string | No | Background color (default: "#ffffff") | | width | number | No | Explicit width for capture | | height | number | No | Explicit height for capture |

Important: fileName Requirements

The fileName prop must include a file extension (.png, .jpg, .jpeg, or .webp). The image format is automatically determined from the file extension.

Examples:

  • fileName="my-image.png" → PNG format
  • fileName="photo.jpg" → JPEG format
  • fileName="picture.webp" → WebP format
  • fileName="my-image" → Error: missing extension

Supported extensions:

  • .png → PNG format
  • .jpg, .jpeg → JPEG format
  • .webp → WebP format

Features

  • ✅ Convert any React component to images in multiple formats (PNG, JPEG, WebP)
  • ✅ Quality control for lossy formats (JPEG, WebP)
  • ✅ Download or share images
  • ✅ Web Share API with clipboard fallback
  • ✅ Render props pattern for custom UI
  • ✅ TypeScript support with full type definitions
  • ✅ Lightweight and easy to use

Sharing Behavior

The share function uses the Web Share API when available (mobile devices, some desktop browsers), and falls back to copying the image to the clipboard on other devices.

Development

# Install dependencies
npm install
# or
yarn install

# Build the project
npm run build
# or
yarn build

# Run tests
npm test
# or
yarn test

License

MIT © Temilayo

Keywords

  • React
  • PNG
  • JPEG
  • WebP
  • Download
  • HTML2Canvas
  • Export
  • Image Generation