1/*! 2 * FilePondPluginImageExifOrientation 1.0.11 3 * Licensed under MIT, https://opensource.org/licenses/MIT/ 4 * Please visit https://pqina.nl/filepond/ for details. 5 */ 6 7/* eslint-disable */ 8 9(function(global, factory) { 10 typeof exports === 'object' && typeof module !== 'undefined' 11 ? (module.exports = factory()) 12 : typeof define === 'function' && define.amd 13 ? define(factory) 14 : ((global = global || self), 15 (global.FilePondPluginImageExifOrientation = factory())); 16})(this, function() { 17 'use strict'; 18 19 // test if file is of type image 20 var isJPEG = function isJPEG(file) { 21 return /^image\/jpeg/.test(file.type); 22 }; 23 24 var Marker = { 25 JPEG: 0xffd8, 26 APP1: 0xffe1, 27 EXIF: 0x45786966, 28 TIFF: 0x4949, 29 Orientation: 0x0112, 30 Unknown: 0xff00 31 }; 32 33 var getUint16 = function getUint16(view, offset) { 34 var little = 35 arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; 36 return view.getUint16(offset, little); 37 }; 38 var getUint32 = function getUint32(view, offset) { 39 var little = 40 arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; 41 return view.getUint32(offset, little); 42 }; 43 44 var getImageOrientation = function getImageOrientation(file) { 45 return new Promise(function(resolve, reject) { 46 var reader = new FileReader(); 47 reader.onload = function(e) { 48 var view = new DataView(e.target.result); 49 50 // Every JPEG file starts from binary value '0xFFD8' 51 if (getUint16(view, 0) !== Marker.JPEG) { 52 // This aint no JPEG 53 resolve(-1); 54 return; 55 } 56 57 var length = view.byteLength; 58 var offset = 2; 59 60 while (offset < length) { 61 var marker = getUint16(view, offset); 62 offset += 2; 63 64 // There's our APP1 Marker 65 if (marker === Marker.APP1) { 66 if (getUint32(view, (offset += 2)) !== Marker.EXIF) { 67 // no EXIF info defined 68 break; 69 } 70 71 // Get TIFF Header 72 var little = getUint16(view, (offset += 6)) === Marker.TIFF; 73 offset += getUint32(view, offset + 4, little); 74 75 var tags = getUint16(view, offset, little); 76 offset += 2; 77 78 for (var i = 0; i < tags; i++) { 79 // found the orientation tag 80 if ( 81 getUint16(view, offset + i * 12, little) === Marker.Orientation 82 ) { 83 resolve(getUint16(view, offset + i * 12 + 8, little)); 84 85 return; 86 } 87 } 88 } else if ((marker & Marker.Unknown) !== Marker.Unknown) { 89 // Invalid 90 break; 91 } else { 92 offset += getUint16(view, offset); 93 } 94 } 95 96 // Nothing found 97 resolve(-1); 98 }; 99 100 // we don't need to read the entire file to get the orientation 101 reader.readAsArrayBuffer(file.slice(0, 64 * 1024)); 102 }); 103 }; 104 105 var IS_BROWSER = (function() { 106 return ( 107 typeof window !== 'undefined' && typeof window.document !== 'undefined' 108 ); 109 })(); 110 var isBrowser = function isBrowser() { 111 return IS_BROWSER; 112 }; 113 114 // 2x1 pixel image 90CW rotated with orientation header 115 var testSrc = 116 'data:image/jpg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4QA6RXhpZgAATU0AKgAAAAgAAwESAAMAAAABAAYAAAEoAAMAAAABAAIAAAITAAMAAAABAAEAAAAAAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////wAALCAABAAIBASIA/8QAJgABAAAAAAAAAAAAAAAAAAAAAxABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQAAPwBH/9k='; 117 118 // should correct orientation if is presented in landscape, in which case the browser doesn't autocorrect 119 var shouldCorrect = undefined; 120 var testImage = isBrowser() ? new Image() : {}; 121 testImage.onload = function() { 122 return (shouldCorrect = testImage.naturalWidth > testImage.naturalHeight); 123 }; 124 testImage.src = testSrc; 125 126 var shouldCorrectImageExifOrientation = function shouldCorrectImageExifOrientation() { 127 return shouldCorrect; 128 }; 129 130 /** 131 * Read Image Orientation Plugin 132 */ 133 var plugin = function plugin(_ref) { 134 var addFilter = _ref.addFilter, 135 utils = _ref.utils; 136 var Type = utils.Type, 137 isFile = utils.isFile; 138 139 // subscribe to file load and append required info 140 addFilter('DID_LOAD_ITEM', function(item, _ref2) { 141 var query = _ref2.query; 142 return new Promise(function(resolve, reject) { 143 // get file reference 144 var file = item.file; 145 146 // if this is not a jpeg image we are not interested 147 if ( 148 !isFile(file) || 149 !isJPEG(file) || 150 !query('GET_ALLOW_IMAGE_EXIF_ORIENTATION') || 151 !shouldCorrectImageExifOrientation() 152 ) { 153 // continue with the unaltered dataset 154 return resolve(item); 155 } 156 157 // get orientation from exif data 158 getImageOrientation(file).then(function(orientation) { 159 item.setMetadata('exif', { orientation: orientation }); 160 resolve(item); 161 }); 162 }); 163 }); 164 165 // Expose plugin options 166 return { 167 options: { 168 // Enable or disable image orientation reading 169 allowImageExifOrientation: [true, Type.BOOLEAN] 170 } 171 }; 172 }; 173 174 // fire pluginloaded event if running in browser, this allows registering the plugin when using async script tags 175 var isBrowser$1 = 176 typeof window !== 'undefined' && typeof window.document !== 'undefined'; 177 if (isBrowser$1) { 178 document.dispatchEvent( 179 new CustomEvent('FilePond:pluginloaded', { detail: plugin }) 180 ); 181 } 182 183 return plugin; 184});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.