philipjscott / simple-thumbnail

A library that produces thumbnails from images, videos and URLs :mag_right:
https://www.npmjs.com/package/simple-thumbnail
MIT License
25 stars 14 forks source link

feat(28): Add write-stream output support #36

Closed philipjscott closed 5 years ago

philipjscott commented 5 years ago

Context

There are situations where users may not want to save the thumbnails to disk, instead, they may want to pipe the image stream to a write stream (eg. S3, HTTP response, etc.).

Users will now be able to pass Stream.Writable as the output argument, eg.

// "app" refers to an Express application
app.get('/give/me/a/thumbnail/please', (req, res) => {
  // cool, huh?
  genThumbnail('path/to/video.webm', res, '150x100')
    .then(() => console.log('Done! :D'))
    .catch(() => console.error('Error! D:'))
})

Objective

References

Lessons learned

philipjscott commented 5 years ago

@cmd430 Is it alright if I add you to the contributors section? :smiley:

cmd430 commented 5 years ago

Yeah no worries :)

EDIT: also i messed around and allowed it to return the raw stream too (i just added a check for bool) but you could make it so if the output is not a string or stream.Writable (maybe just pass null ?) then return the raw stream

see: https://github.com/cmd430/simple-thumbnail/commit/f879026be0ec7ba873fdbc488ece57d686a6c7f0

also sorry about the shitty edits I was doing some experimenting for a project :P

philipjscott commented 5 years ago

:tada: This PR is included in version 1.4.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: