Wrapper for pica to work with blobs, with some sugar.
This is pica
wrapper for convenient work with images from file input fields.
While pica
works with raw bitmaps, this package operates with "image files".
Additional features are:
- [jpeg] Apply orientation to downscaled result.
- [jpeg] Keep metadata, but with patched orientation & removed original color profile.
- Easy to monkey-patch for your needs.
npm install image-blob-reduce
const reduce = require('image-blob-reduce')();
//...
reduce
.toBlob(image_blob, { maxWidth: 1000, maxHeight: 1000 })
.then(blob => { ... });
Create new reducer. Options:
pica
- instance ofpica
, if you wish different defaults or shareable webworkers pool.
Short call: require('image_blob_reduce')()
Downscale image to fit into maxWidth
*maxHeight
size. If blob contains jpeg, then
orientation is applied and metadata from original image reused (with minimal
change).
Options:
- maxWidth - max allowed image width.
- maxHeight - max allowed image height.
- pica
.resize()
options -alpha
,unsharpAmount
,unsharpRadius
,unsharpThreshold
,cancelToken
The same as .toBlob()
, but with canvas output.
require('./lib/utils')
, to simplify modifications.
More relinking:
ImageBlobReduce.pica
=>require('pica')
ImageBlobReduce.utils
=>require('./lib/utils')