|
34 | 34 | var originalTransformCoordinates = loadImage.transformCoordinates
|
35 | 35 | var originalGetTransformedOptions = loadImage.getTransformedOptions
|
36 | 36 |
|
| 37 | + ;(function () { |
| 38 | + // black 2x1 JPEG, with the following meta information set: |
| 39 | + // - EXIF Orientation: 6 (Rotated 90° CCW) |
| 40 | + var testImageURL = |
| 41 | + 'data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAA' + |
| 42 | + 'AAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA' + |
| 43 | + 'QEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE' + |
| 44 | + 'BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/x' + |
| 45 | + 'ABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAA' + |
| 46 | + 'AAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q==' |
| 47 | + var img = document.createElement('img') |
| 48 | + img.onload = function () { |
| 49 | + // Check if browser supports automatic image orientation: |
| 50 | + loadImage.orientation = img.width === 1 && img.height === 2 |
| 51 | + } |
| 52 | + img.src = testImageURL |
| 53 | + })() |
| 54 | + |
37 | 55 | // Determines if the target image should be a canvas element:
|
38 | 56 | loadImage.hasCanvasOption = function (options) {
|
39 | 57 | return (
|
40 |
| - !!options.orientation || originalHasCanvasOption.call(loadImage, options) |
| 58 | + (!!options.orientation === true && !loadImage.orientation) || |
| 59 | + (options.orientation > 1 && options.orientation < 9) || |
| 60 | + originalHasCanvasOption.call(loadImage, options) |
41 | 61 | )
|
42 | 62 | }
|
43 | 63 |
|
44 | 64 | // Determines if meta data should be loaded automatically:
|
45 | 65 | loadImage.hasMetaOption = function (options) {
|
46 | 66 | return (
|
47 |
| - (options && options.orientation === true) || |
| 67 | + (options && options.orientation === true && !loadImage.orientation) || |
48 | 68 | originalHasMetaOption.call(loadImage, options)
|
49 | 69 | )
|
50 | 70 | }
|
|
115 | 135 | var orientation = options.orientation
|
116 | 136 | var newOptions
|
117 | 137 | var i
|
118 |
| - if (orientation === true && data && data.exif) { |
119 |
| - orientation = data.exif.get('Orientation') |
| 138 | + if (orientation === true) { |
| 139 | + if (loadImage.orientation) { |
| 140 | + // Browser supports automatic image orientation |
| 141 | + return options |
| 142 | + } |
| 143 | + orientation = data && data.exif && data.exif.get('Orientation') |
120 | 144 | }
|
121 | 145 | if (!(orientation > 1 && orientation < 9)) {
|
122 | 146 | return options
|
|
0 commit comments