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

remark-picture

v1.1.1

Published

A Remark plugin that converts Markdown `<img>` elements into modern `<picture>` elements

Readme

📸 remark-picture

npm version License: MIT

A Remark plugin that converts Markdown <img> elements into modern <picture> elements with responsive and next-gen image formats (WebP, AVIF, etc.).

Works great together with picture-converter — a companion tool that converts your legacy .png, .jpg, and .gif files into efficient next-gen formats.

Why use remark-picture?

Traditional Markdown images are static and can’t take advantage of modern browser optimizations. With remark-picture, you can:

✅ Automatically generate <picture> elements from ![alt](path.png)
✅ Serve WebP and AVIF images for smaller size and faster loading
✅ Define responsive sources via media queries
✅ Add pixel-density variants (1x, 2x, etc.)
✅ Use custom URL templates to integrate with CDNs or build pipelines
✅ Stay fully typed with TypeScript

Installation

npm install remark-picture

🚀 Quick Start

import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
import remarkPicture from 'remark-picture'

const file = await unified()
  .use(remarkParse)
  .use(remarkPicture)
  .use(remarkRehype)
  .use(rehypeStringify)
  .process('![Sunset](images/sunset.jpg)')

console.log(String(file))

✨ Example

Input Markdown

![Sunset](images/sunset.jpg)

Output HTML

<picture>
  <source srcset="images/sunset.avif" type="image/avif">
  <source srcset="images/sunset.webp" type="image/webp">
  <img src="images/sunset.jpg" alt="Sunset">
</picture>

With Media Queries and Densities

<picture>
  <source srcset="/mobile/sunset.webp, /mobile/[email protected] 2x" 
          type="image/webp" media="(max-width: 480px)">
  <source srcset="/desktop/sunset.webp, /desktop/[email protected] 2x" 
          type="image/webp" media="(min-width: 481px)">
  <img src="images/sunset.jpg" alt="Sunset">
</picture>

🧩 Usage

import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
import remarkPicture from 'remark-picture'

const file = await unified()
  .use(remarkParse)
  .use(remarkPicture, {
    formatMapping: {
      jpg: ['avif', 'webp'],
      png: ['webp']
    },
    media: {
      mobile: {
        urlTemplate: '/mobile/{basename}.{ext}',
        query: '(max-width: 480px)',
        pixelDensity: [1, 2]
      },
      desktop: {
        urlTemplate: '/desktop/{basename}.{ext}',
        query: '(min-width: 481px)',
        pixelDensity: [1, 2]
      }
    }
  })
  .use(remarkRehype)
  .use(rehypeStringify)
  .process('![Sunset](images/sunset.jpg)')

console.log(String(file))

⚙️ Options

| Option | Type | Default | Description | | ------------------ |----------------------------------------------------------| -------------------------- | -------------------------------------------------------------------------- | | formatMapping | Record<ImageExtension, ImageExtension[]> | { jpg/png → avif, webp } | Defines which formats to generate from which source | | media | Record<string, { urlTemplate, query?, pixelDensity? }> | – | Define responsive sources (e.g. mobile vs desktop) | | pixelDensity | number | 1 | Default pixel density multiplier | | imageUrlTemplate | string | – | Template for generated image URLs, e.g. "/images/{basename}@{pd}x.{ext}" | | imageToPicture | (image, convert, pictureBuilder) => Picture | – | Custom function for full control over generation |

🔧 URL Templating

Template strings (for imageUrlTemplate or media.urlTemplate) can use:

| Placeholder | Example | Description | | --------------- | ---------------------- |----------------------------| | {dir} | /assets/images/ | Original image directory | | {basename} | photo | Filename without extension | | {originalExt} | jpg | Original image extension | | {ext} | webp | Target image extension | | {pd} | 2 | Pixel density (e.g. 1, 2) | | {basepath} | /assets/images/photo | Directory + basename |

Example:

imageUrlTemplate: "/cdn/{basename}@{pd}x.{ext}"

🧩 Custom Conversion

You can fully control how <picture> elements are generated:

const adaptiveOptions: Options = {
  formatMapping: {png: ['webp']},
  media: {
    mobile: {
      query: '(max-width: 480px)',
      urlTemplate: '{dir}mobile/{basename}-{pd}x.{ext}',
      pixelDensity: [2, 3]
    },
    desktop: {
      query: '(min-width: 481px)',
      urlTemplate: '{basepath}.{ext}'
    }
  }
}

function customImageToPicture(image: Image, convert: ConvertFn): Picture | PictureBuilder | undefined {
  if (image.url.includes('icon')) {
    // skip conversion for icons
    return undefined
  }
  if (image.url.startsWith('adaptive-images/')) {
    // use custom options
    return convert(adaptiveOptions)
  }
  // use default behavior
  return convert()
}

...
use(remarkPicture, {imageToPicture: customImageToPicture})

🧰 Default Format Mapping

{
  png: ['avif', 'webp'],
  jpg: ['avif', 'webp'],
  jpeg: ['avif', 'webp'],
  gif: ['webp'],
  apng: ['webp']
}

Contributing

Contributions, issues, and feature requests are welcome!
Feel free to open an issue or submit a pull request.

Related

Picture Converter — converts old image formats (.png, .jpg, .gif) to modern, efficient formats (.webp, .avif) automatically.

License

MIT © Anatoly Nechaev