Skip to content

Commit 0548f3b

Browse files
committed
Use 3x2 test image to validate EXIF orientation.
1 parent 4a6fe05 commit 0548f3b

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed

test/test.js

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,31 @@
1616
'use strict'
1717

1818
var canCreateBlob = !!window.dataURLtoBlob
19-
// 80x60px GIF image (color black, base64 data):
19+
// black 80x60 GIF:
2020
var b64DataGIF =
2121
'R0lGODdhUAA8AIABAAAAAP///ywAAAAAUAA8AAACS4SPqcvtD6' +
2222
'OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofE' +
2323
'ovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5PKsAAA7'
2424
var imageUrlGIF = 'data:image/gif;base64,' + b64DataGIF
2525
var blobGIF = canCreateBlob && window.dataURLtoBlob(imageUrlGIF)
26-
// black/white 1x2px JPEG, with the following meta information set:
26+
// black+white 3x2 JPEG, with the following meta information set:
2727
// - EXIF Orientation: 6 (Rotated 90° CCW)
2828
// - IPTC ObjectName: blueimp.net
2929
// Meta information has been set via exiftool (exiftool.org):
3030
// exiftool -all= -Orientation#=6 -YCbCrPositioning= -ResolutionUnit= \
31-
// -YResolution= -XResolution= -ObjectName=blueimp.net black+white-1x2.jpg
31+
// -YResolution= -XResolution= -ObjectName=blueimp.net black+white-3x2.jpg
32+
// Image data layout (B=black, F=white):
33+
// BFF
34+
// BBB
3235
var b64DataJPEG =
3336
'/9j/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAYAAAAAAAD/7QA0UGhvdG9zaG9wIDMu' +
34-
'MAA4QklNBAQAAAAAABccAgUAC2JsdWVpbXAubmV0HAIAAAIABAD/2wCEAAEBAQEBAQIBAQID' +
35-
'AgICAwQDAwMDBAYEBAQEBAYHBgYGBgYGBwcHBwcHBwcICAgICAgJCQkJCQsLCwsLCwsLCwsB' +
36-
'AgICAwMDBQMDBQsIBggLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsL' +
37-
'CwsLCwsLCwsLC//AABEIAAIAAQMBIgACEQEDEQH/xABSAAEBAAAAAAAAAAAAAAAAAAAAChAB' +
38-
'AAAHAAAAAAAAAAAAAAAAAAUHCRlYltQBAQAAAAAAAAAAAAAAAAAAAAARAQAAAAAAAAAAAAAA' +
39-
'AAAAAAD/2gAMAwEAAhEDEQA/AK+bT1LLGmVWmwjlAB//2Q=='
37+
'MAA4QklNBAQAAAAAABccAgUAC2JsdWVpbXAubmV0HAIAAAIABAD/2wCEAAEBAQEBAQEBAQEB' +
38+
'AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB' +
39+
'AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB' +
40+
'AQEBAQEBAQEBAf/AABEIAAIAAwMBEQACEQEDEQH/xABRAAEAAAAAAAAAAAAAAAAAAAAKEAEB' +
41+
'AQADAQEAAAAAAAAAAAAGBQQDCAkCBwEBAAAAAAAAAAAAAAAAAAAAABEBAAAAAAAAAAAAAAAA' +
42+
'AAAAAP/aAAwDAQACEQMRAD8AG8T9NfSMEVMhQvoP3fFiRZ+MTHDifa/95OFSZU5OzRzxkyej' +
43+
'v8ciEfhSceSXGjS8eSdLnZc2HDm4M3BxcXwH/9k='
4044
var imageUrlJPEG = 'data:image/jpeg;base64,' + b64DataJPEG
4145
var blobJPEG = canCreateBlob && window.dataURLtoBlob(imageUrlJPEG)
4246
/**
@@ -840,28 +844,42 @@
840844
expect(data.exif).to.be.ok
841845
expect(data.exif.get('Orientation')).to.equal(6)
842846
expect(img.width).to.equal(2)
843-
expect(img.height).to.equal(1)
844-
var imageData = img.getContext('2d').getImageData(0, 0, 2, 2).data
845-
// 0:0 opaque white
846-
expect(imageData[0]).to.equal(255)
847-
expect(imageData[1]).to.equal(255)
848-
expect(imageData[2]).to.equal(255)
847+
expect(img.height).to.equal(3)
848+
// Image data layout after orientation (B=black, F=white):
849+
// BB
850+
// BF
851+
// BF
852+
var imageData = img.getContext('2d').getImageData(0, 0, 2, 3).data
853+
// 0:0 opaque black
854+
expect(imageData[0]).to.equal(0)
855+
expect(imageData[1]).to.equal(0)
856+
expect(imageData[2]).to.equal(0)
849857
expect(imageData[3]).to.equal(255)
850858
// 0:1 opaque black
851859
expect(imageData[0 + 4]).to.equal(0)
852860
expect(imageData[1 + 4]).to.equal(0)
853861
expect(imageData[2 + 4]).to.equal(0)
854862
expect(imageData[3 + 4]).to.equal(255)
855-
// 1:0 transparent black (off canvas)
863+
// 1:0 opaque black
856864
expect(imageData[0 + 8]).to.equal(0)
857865
expect(imageData[1 + 8]).to.equal(0)
858866
expect(imageData[2 + 8]).to.equal(0)
859-
expect(imageData[3 + 8]).to.equal(0)
860-
// 1:1 transparent black (off canvas)
861-
expect(imageData[0 + 12]).to.equal(0)
862-
expect(imageData[1 + 12]).to.equal(0)
863-
expect(imageData[2 + 12]).to.equal(0)
864-
expect(imageData[3 + 12]).to.equal(0)
867+
expect(imageData[3 + 8]).to.equal(255)
868+
// 1:1 opaque white
869+
expect(imageData[0 + 12]).to.equal(255)
870+
expect(imageData[1 + 12]).to.equal(255)
871+
expect(imageData[2 + 12]).to.equal(255)
872+
expect(imageData[3 + 12]).to.equal(255)
873+
// 2:0 opaque black
874+
expect(imageData[0 + 16]).to.equal(0)
875+
expect(imageData[1 + 16]).to.equal(0)
876+
expect(imageData[2 + 16]).to.equal(0)
877+
expect(imageData[3 + 16]).to.equal(255)
878+
// 2:1 opaque white
879+
expect(imageData[0 + 20]).to.equal(255)
880+
expect(imageData[1 + 20]).to.equal(255)
881+
expect(imageData[2 + 20]).to.equal(255)
882+
expect(imageData[3 + 20]).to.equal(255)
865883
done()
866884
},
867885
{ orientation: true }
@@ -875,10 +893,10 @@
875893
blobJPEG,
876894
function (img) {
877895
expect(img.width).to.equal(20)
878-
expect(img.height).to.equal(10)
896+
expect(img.height).to.equal(30)
879897
done()
880898
},
881-
{ orientation: true, minWidth: 20, minHeight: 10 }
899+
{ orientation: true, minWidth: 20, minHeight: 30 }
882900
)
883901
).to.be.ok
884902
})
@@ -1027,8 +1045,7 @@
10271045
loadImage(imageUrlJPEG, function (img, data) {
10281046
expect(data.imageHead).to.be.undefined
10291047
expect(data.exif).to.be.undefined
1030-
expect(img.width).to.equal(1)
1031-
expect(img.height).to.equal(2)
1048+
expect(data.iptc).to.be.undefined
10321049
done()
10331050
})
10341051
).to.be.ok

0 commit comments

Comments
 (0)