From 2d17301642af655ff080a6deec2c223196212811 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 29 Mar 2019 15:38:20 +0100 Subject: [PATCH] Add ImageResizer#loadFile --- .../js/WoltLabSuite/Core/ImageResizer.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/ImageResizer.js b/wcfsetup/install/files/js/WoltLabSuite/Core/ImageResizer.js index 6a914e6d0b..d572ea29ed 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/ImageResizer.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/ImageResizer.js @@ -105,6 +105,47 @@ define([ }); }, + /** + * Loads the given file into an image object and parses Exif information. + * + * @param {File} file the file to load + * @returns {Promise} resulting image data + */ + loadFile: function (file) { + var exif = undefined; + if (file.type === 'image/jpeg') { + // Extract EXIF data + exif = ExifUtil.getExifBytesFromJpeg(file); + } + + var loader = new Promise(function (resolve, reject) { + var reader = new FileReader(); + var image = new Image(); + + reader.addEventListener('load', function () { + image.src = reader.result; + }); + + reader.addEventListener('error', function () { + reader.abort(); + reject(reader.error); + }); + + image.addEventListener('error', reject); + + image.addEventListener('load', function () { + resolve(image); + }); + + reader.readAsDataURL(file); + }); + + return Promise.all([ exif, loader ]) + .then(function (result) { + return { exif: result[0], image: result[1] }; + }); + }, + /** * Downscales an image given as File object. * -- 2.20.1