mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-20 02:08:57 +00:00
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
28 lines
738 B
JavaScript
28 lines
738 B
JavaScript
// 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);
|
|
});
|
|
};
|