# simple-thumbnail

> Produce thumbnails from images, videos and URLs

Latest version **1.6.5** (published 2020-01-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-thumbnail
pnpm add simple-thumbnail
yarn add simple-thumbnail
bun add simple-thumbnail
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.5 |
| Published | 2020-01-19 |
| First published | 2018-08-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 29.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 24 |
| Author | Philip Scott |
| Maintainers | scottyfillups |
| Keywords | thumbnail, video, ffmpeg, picture, image, resize, webm, mp4, png, preview, url |

## Links

- npm: https://www.npmjs.com/package/simple-thumbnail
- Repository: https://github.com/ScottyFillups/simple-thumbnail
- Homepage: https://github.com/ScottyFillups/simple-thumbnail#readme
- Issues: https://github.com/ScottyFillups/simple-thumbnail/issues
- npm.io page: https://npm.io/package/simple-thumbnail

## Dependencies (1)

- [duplexify](https://npm.io/package/duplexify.md) ^4.0.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.6.5 (latest) — 2020-01-19
- 1.6.4 — 2020-01-19
- 1.6.3 — 2019-12-29
- 1.6.2 — 2019-12-18
- 1.6.1 — 2019-08-27
- 1.6.0 — 2019-08-21
- 1.5.7 — 2019-08-14
- 1.5.6 — 2019-07-13
- 1.5.5 — 2019-07-12
- 1.5.4 — 2019-07-10
- 1.5.3 — 2019-07-10
- 1.5.2 — 2019-06-22
- 1.5.1 — 2019-05-12
- 1.5.0 — 2019-05-11
- 1.4.5 — 2019-01-19
- … 18 more at https://npm.io/package/simple-thumbnail/versions

## README

# simple-thumbnail 
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors)
[![npm version](https://badge.fury.io/js/simple-thumbnail.svg)](https://badge.fury.io/js/simple-thumbnail)
[![Build Status](https://travis-ci.org/ScottyFillups/simple-thumbnail.svg?branch=master)](https://travis-ci.org/ScottyFillups/simple-thumbnail)
[![Coverage Status](https://coveralls.io/repos/github/ScottyFillups/simple-thumbnail/badge.svg?branch=master)](https://coveralls.io/github/ScottyFillups/simple-thumbnail?branch=master)
[![install size](https://packagephobia.now.sh/badge?p=simple-thumbnail)](https://packagephobia.now.sh/result?p=simple-thumbnail)

A minimal library that produces thumbnails from images and videos using FFmpeg.

## Installation

```bash
$ npm install simple-thumbnail --save
```

## Usage

```js
const fs = require('fs')
const genThumbnail = require('simple-thumbnail')

// promise
genThumbnail('path/to/image.png', 'output/file/path.png', '250x?')
  .then(() => console.log('done!'))
  .catch(err => console.error(err))

// async/await
async function run () {
  try {
    await genThumbnail('http://www.example.com/foo.webm', 'output/file/path.png', '250x?')
    console.log('Done!')
  } catch (err) {
    console.error(err)
  }
}

run()

// genThumbnail also supports piping to write streams, so you can do this with Express!
app.get('/some/endpoint', (req, res) => {
  genThumbnail('path/to/video.webm', res, '150x100')
    .then(() => console.log('done!'))
    .catch(err => console.error(err))
})

// duplex streams
fs.createReadStream('path/to/image')
  .pipe(genThumbnail(null, null, '250x?'))
  .pipe(fs.createWriteStream('output/file/path.jpg'))
```

## Getting FFmpeg

For those who don't have FFmpeg installed, there's an NPM package that installs it for you: https://www.npmjs.com/package/ffmpeg-static

```js
const ffmpeg = require('ffmpeg-static')
const genThumbnail = require('simple-thumbnail')

async function download () {
  await genThumbnail('https://www.w3schools.com/Html/mov_bbb.webm', 'bunny.webm', '150x?', {
    path: ffmpeg.path
  })
  
  console.log('Done!')
}

download()
```

## API

#### genThumbnail(input, output, size, [config])

Returns of a `Promise` which resolves on thumbnail creation, or a `stream.Duplex` (see below).

#### input

Type: `String | stream.Readable | Null`

The URL, file path, or read-stream of an image or video. If both the input and output are null, then `genThumbnail` will return a `stream.Duplex`.

#### output

Type: `String | stream.Writable | Null`

The file path of the generated thumbnail, a write-stream, or null. If null, `genThumbnail` will resolve to a read-stream that you can pipe somewhere. If you're specifying a file path, make sure the directories exist.

#### size

Type: `String`

The dimensions of the generated thumbnail. The `size` argument may have one of the following formats:

* `150x100`: set a fixed output size.
* `150x?`: set a fixed width and compute the height automatically.
* `?x100`: set a fixed height and compute the width automatically.
* `50%`: rescale both width and height to given percentage.

#### config

Type: `Object`

A configuration object, see details below.

#### config.path

Type: `String`

The path of the `ffmpeg` binary. If omitted, the path will be set to the `FFMPEG_PATH` environment variable. If the environment variable is not set, `ffmpeg` will be invoked directly (ie. `ffmpeg [...]`).

#### config.seek

Type: `String`

Seeks the video to the provided time. The time must be in the following form: `hh:mm:ss[.ms]`, eg. `00:00:42.23`. If omitted, the video time will be set to `00:00:00` (ie. the first frame).

#### config.args

Type: `Array<String>`

FFmpeg arguments that override the synthetic arguments created by `simple-thumbnail`; you'll likely need to pass include your own `-i` flag, `-y` flag, etc.

## Contributors

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
| [<img src="https://avatars2.githubusercontent.com/u/18666879?v=4" width="100px;"/><br /><sub><b>Philip Scott</b></sub>](http://scottyfillups.io)<br />[💻](https://github.com/ScottyFillups/simple-thumbnail/commits?author=ScottyFillups "Code") [⚠️](https://github.com/ScottyFillups/simple-thumbnail/commits?author=ScottyFillups "Tests") [📖](https://github.com/ScottyFillups/simple-thumbnail/commits?author=ScottyFillups "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/2668906?v=4" width="100px;"/><br /><sub><b>cmd430</b></sub>](https://github.com/cmd430)<br />[💻](https://github.com/ScottyFillups/simple-thumbnail/commits?author=cmd430 "Code") [🤔](#ideas-cmd430 "Ideas, Planning, & Feedback") | [<img src="https://avatars0.githubusercontent.com/u/682269?v=4" width="100px;"/><br /><sub><b>Andre-John Mas</b></sub>](http://terra-azure.org)<br />[💻](https://github.com/ScottyFillups/simple-thumbnail/commits?author=ajmas "Code") [🐛](https://github.com/ScottyFillups/simple-thumbnail/issues?q=author%3Aajmas "Bug reports") |
| :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->
<!-- ALL-CONTRIBUTORS-LIST: START - Do not remove or modify this section -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification.

Contributions of any kind are welcome!

## Contributing

See [CONTRIBUTING.md](https://github.com/ScottyFillups/simple-thumbnail/blob/master/CONTRIBUTING.md).

---
_Source: https://npm.io/package/simple-thumbnail · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
