UNPKG

1.89 kBMarkdownView Raw
1# simple-thumbnail
2
3[![npm version](https://badge.fury.io/js/simple-thumbnail.svg)](https://badge.fury.io/js/simple-thumbnail)
4[![Build Status](https://travis-ci.org/ScottyFillups/simple-thumbnail.svg?branch=master)](https://travis-ci.org/ScottyFillups/simple-thumbnail)
5[![Coverage Status](https://coveralls.io/repos/github/ScottyFillups/simple-thumbnail/badge.svg?branch=master)](https://coveralls.io/github/ScottyFillups/simple-thumbnail?branch=master)
6[![install size](https://packagephobia.now.sh/badge?p=simple-thumbnail)](https://packagephobia.now.sh/result?p=simple-thumbnail)
7
8A minimal library that produces a thumbnail image from a video's first frame using `ffmpeg`.
9
10## Installation
11
12```bash
13$ yarn add simple-thumbnail
14
15# Or,
16
17$ npm install simple-thumbnail --save
18```
19
20## Usage
21
22```js
23const genThumbnail = require('simple-thumbnail')
24
25// promise
26genThumbnail('path/to/video.webm', 'output/file/path.png', '250x?')
27 .then(() => console.log('done!'))
28 .catch(err => console.error(err))
29
30// async/await
31async function run () {
32 try {
33 await genThumbnail('http://www.example.com/foo.webm', 'output/file/path.png', '250x?')
34 console.log('Done!')
35 } catch (err) {
36 console.error(err)
37 }
38}
39
40run()
41```
42
43## API
44
45#### genThumbnail(input, output, size)
46
47Returns of a `Promise` which resolves on thumbnail creation.
48
49#### input
50
51Type: `String | stream.Readable`
52
53The URL, file path, or read-stream of a video.
54
55#### output
56
57Type: `String`
58
59The file path of the generated thumbnail, assumes directories exist.
60
61#### size
62
63Type: `String`
64
65The dimensions of the generated thumbnail. The `size` argument may have one of the following formats:
66
67* `150x100`: set a fixed output size.
68* `150x?`: set a fixed width and compute the height automatically.
69* `?x100`: set a fixed height and compute the width automatically.
70* `50%`: rescale both width and height to given percentage.