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 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-thumbnail-fork

v0.0.0-development

Published

Produce thumbnails from images, videos and URLs

Downloads

1

Readme

simple-thumbnail

All Contributors npm version Build Status Coverage Status install size

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

Installation

$ npm install simple-thumbnail --save

Usage

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

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

| Philip Scott💻 ⚠️ 📖 | cmd430💻 🤔 | Andre-John Mas💻 🐛 | | :---: | :---: | :---: |

This project follows the all-contributors specification.

Contributions of any kind are welcome!

Contributing

See CONTRIBUTING.md.