@@ -64,23 +64,43 @@ Exif orientation values to correctly display the letter F:
6464 var originalTransformCoordinates = loadImage . transformCoordinates
6565 var originalGetTransformedOptions = loadImage . getTransformedOptions
6666
67- ; ( function ( ) {
68- // black 2x1 JPEG, with the following meta information set:
67+ ; ( function ( $ ) {
68+ // black+white 3x2 JPEG, with the following meta information set:
6969 // - EXIF Orientation: 6 (Rotated 90° CCW)
70+ // Image data layout (B=black, F=white):
71+ // BFF
72+ // BBB
7073 var testImageURL =
7174 'data:image/jpeg;base64,/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAA' +
7275 'AAAD/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA' +
7376 'QEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE' +
74- 'BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAgMBEQACEQEDEQH/x' +
75- 'ABKAAEAAAAAAAAAAAAAAAAAAAALEAEAAAAAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAAAAAAA' +
76- 'AAAAAEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwA/8H//2Q=='
77+ 'BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAIAAwMBEQACEQEDEQH/x' +
78+ 'ABRAAEAAAAAAAAAAAAAAAAAAAAKEAEBAQADAQEAAAAAAAAAAAAGBQQDCAkCBwEBAAAAAAA' +
79+ 'AAAAAAAAAAAAAABEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEQMRAD8AG8T9NfSMEVMhQ' +
80+ 'voP3fFiRZ+MTHDifa/95OFSZU5OzRzxkyejv8ciEfhSceSXGjS8eSdLnZc2HDm4M3BxcXw' +
81+ 'H/9k='
7782 var img = document . createElement ( 'img' )
7883 img . onload = function ( ) {
79- // Check if browser supports automatic image orientation:
80- loadImage . orientation = img . width === 1 && img . height === 2
84+ // Check if the browser supports automatic image orientation:
85+ $ . orientation = img . width === 2 && img . height === 3
86+ if ( $ . orientation ) {
87+ var canvas = document . createElement ( 'canvas' )
88+ canvas . width = canvas . height = 1
89+ var ctx = canvas . getContext ( '2d' )
90+ ctx . drawImage ( img , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 )
91+ // Check if the source image coordinates (sX, sY, sWidth, sHeight) are
92+ // correctly applied to the auto-orientated image, which should result
93+ // in a white opaque pixel (e.g. in Safari).
94+ // Browsers that show a transparent pixel (e.g. Chromium) fail to crop
95+ // auto-oriented images correctly and require a workaround, e.g.
96+ // drawing the complete source image to an intermediate canvas first.
97+ // See https://bugs.chromium.org/p/chromium/issues/detail?id=1074354
98+ $ . orientationCropBug =
99+ ctx . getImageData ( 0 , 0 , 1 , 1 ) . data . toString ( ) !== '255,255,255,255'
100+ }
81101 }
82102 img . src = testImageURL
83- } ) ( )
103+ } ) ( loadImage )
84104
85105 /**
86106 * Determines if the image requires orientation.
0 commit comments