From: Tim Düsterhus Date: Fri, 29 Mar 2019 14:38:20 +0000 (+0100) Subject: Add ImageResizer#loadFile X-Git-Tag: 5.2.0_Alpha_1~124^2~5 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2d17301642af655ff080a6deec2c223196212811;p=GitHub%2FWoltLab%2FWCF.git Add ImageResizer#loadFile --- 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. *