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 |
|
8 | A 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
|
23 | const genThumbnail = require('simple-thumbnail')
|
24 |
|
25 | // promise
|
26 | genThumbnail('path/to/video.webm', 'output/file/path.png', '250x?')
|
27 | .then(() => console.log('done!'))
|
28 | .catch(err => console.error(err))
|
29 |
|
30 | // async/await
|
31 | async 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 |
|
40 | run()
|
41 | ```
|
42 |
|
43 | ## API
|
44 |
|
45 | #### genThumbnail(input, output, size)
|
46 |
|
47 | Returns of a `Promise` which resolves on thumbnail creation.
|
48 |
|
49 | #### input
|
50 |
|
51 | Type: `String | stream.Readable`
|
52 |
|
53 | The URL, file path, or read-stream of a video.
|
54 |
|
55 | #### output
|
56 |
|
57 | Type: `String`
|
58 |
|
59 | The file path of the generated thumbnail, assumes directories exist.
|
60 |
|
61 | #### size
|
62 |
|
63 | Type: `String`
|
64 |
|
65 | The 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.
|