Package Exports
- thumbsup-downsize
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (thumbsup-downsize) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
thumbsup-downsize
Convert / resize / transcode / down-sample photos & videos to be web-friendly
This is one of the core modules of thumbsup.github.io.
Setup
npm install thumbsup-downsize --saveThis module requires GraphicsMagick and FFMpeg on the target system, available in the system path.
Usage
const downsize = require('thumbsup-downsize')
const options = { height: 100, width: 100 }
downsize.image('source.tiff', 'thumb.jpg', options, (err) => {
console.log(err || 'Thumbnail created successfully')
})API
.image
.image(source, target, options, callback)Processes the image in source and creates a new image in target.
The image is appropriately converted if needed based on the target file extension.
Optionally specify options to resize the image:
// don't resize, just convert
opts = {}
// proportionally resize the photo to a maximum height
opts = {height}
// proportionally resize the photo to a maximum width
opts = {width}
// resize and crop the photo to exactly height x width (aspect ratio preserved)
opts = {height, width}.still
.still(source, target, options, callback)Extract a single frame from the video in source, and writes the image to target.
Optionally specify options to resize the image:
// don't resize
opts = {}
// proportionally resize the still to a maximum height
opts = {height}
// proportionally resize the still to a maximum width
opts = {width}
// resize and crop the still to exactly height x width (aspect ratio preserved)
opts = {height, width}.video
.video(source, target, options, callback)Transcodes the video in source to a web-friendly format and lower bitrate, and writes it in target.
Currently doesn't support any options, simply pass an empty hash ({}).
The .video() call returns an EventEmitter
to follow the progress of the conversion, since it can take a long time.
const emitter = downsize.video(/* ... */)
emitter.on('progress', percent => console.log(`${percent}%`))Contributing
Image/video resizing is hard to unit test. Instead, this repo contains an integration test suite made of many different resized files, covering different file formats and edge cases.
When submitting a change, make sure you run the build locally.
npm testIf you don't have all dependencies installed, you can also run the tests in Docker.
docker build -t downsize-test .
docker run downsize-test