Add `autoOrientImage` module
This module exposes `loadImage` with a `Promise` based interface and pre- populates `orientation: true` option to auto-orient input. Returns data URL as string. The module uses a named export as refactoring references of modules with `default` (`module.exports`) export references can be error-prone. See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
This commit is contained in:
parent
c77063afc6
commit
4431854923
|
@ -0,0 +1,27 @@
|
||||||
|
// File | Blob | URLString -> LoadImageOptions -> Promise<DataURLString>
|
||||||
|
//
|
||||||
|
// Documentation for `options`:
|
||||||
|
// https://github.com/blueimp/JavaScript-Load-Image/tree/v2.18.0#options
|
||||||
|
exports.autoOrientImage = (fileOrBlobOrURL, options) => {
|
||||||
|
const optionsWithAutoOrient = Object.assign(
|
||||||
|
{},
|
||||||
|
options, {
|
||||||
|
canvas: true,
|
||||||
|
orientation: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
window.loadImage(fileOrBlobOrURL, canvasOrError => {
|
||||||
|
if (canvasOrError.type === 'error') {
|
||||||
|
const error = canvasOrError;
|
||||||
|
reject(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const canvas = canvasOrError;
|
||||||
|
const dataURL = canvas.toDataURL();
|
||||||
|
resolve(dataURL);
|
||||||
|
}, optionsWithAutoOrient);
|
||||||
|
});
|
||||||
|
};
|
|
@ -71,6 +71,8 @@
|
||||||
window.nodeNotifier = require('node-notifier');
|
window.nodeNotifier = require('node-notifier');
|
||||||
|
|
||||||
window.loadImage = require('blueimp-load-image');
|
window.loadImage = require('blueimp-load-image');
|
||||||
|
const {autoOrientImage} = require('./js/modules/autoOrientImage');
|
||||||
|
window.autoOrientImage = autoOrientImage;
|
||||||
|
|
||||||
// We pull this in last, because the native module involved appears to be sensitive to
|
// We pull this in last, because the native module involved appears to be sensitive to
|
||||||
// /tmp mounted as noexec on Linux.
|
// /tmp mounted as noexec on Linux.
|
||||||
|
|
Loading…
Reference in New Issue