Add `options` for `autoOrientImage` output type / quality
This commit is contained in:
parent
87745b5586
commit
ff04bad851
|
@ -1,13 +1,24 @@
|
|||
/* jshint ignore:start */
|
||||
|
||||
const loadImage = require('blueimp-load-image');
|
||||
|
||||
// File | Blob | URLString -> LoadImageOptions -> Promise<DataURLString>
|
||||
//
|
||||
// Documentation for `options`:
|
||||
// Documentation for `options` (`LoadImageOptions`):
|
||||
// https://github.com/blueimp/JavaScript-Load-Image/tree/v2.18.0#options
|
||||
exports.autoOrientImage = (fileOrBlobOrURL, options) => {
|
||||
const optionsWithAutoOrient = Object.assign(
|
||||
{},
|
||||
options, {
|
||||
exports.autoOrientImage = (fileOrBlobOrURL, options = {}) => {
|
||||
const {quality} = options;
|
||||
if (typeof quality !== 'undefined' && typeof quality !== 'number') {
|
||||
throw new TypeError(`\`options.quality\` must be a number; got ${typeof quality}`);
|
||||
}
|
||||
|
||||
const optionsWithDefaults = Object.assign(
|
||||
{
|
||||
type: 'image/jpeg',
|
||||
quality: 0.8,
|
||||
},
|
||||
options,
|
||||
{
|
||||
canvas: true,
|
||||
orientation: true,
|
||||
}
|
||||
|
@ -22,8 +33,12 @@ exports.autoOrientImage = (fileOrBlobOrURL, options) => {
|
|||
}
|
||||
|
||||
const canvas = canvasOrError;
|
||||
const dataURL = canvas.toDataURL();
|
||||
const dataURL = canvas.toDataURL(
|
||||
optionsWithDefaults.type,
|
||||
optionsWithDefaults.quality
|
||||
);
|
||||
|
||||
resolve(dataURL);
|
||||
}, optionsWithAutoOrient);
|
||||
}, optionsWithDefaults);
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue