@webex/helper-image 3.0.0-beta.8 → 3.0.0-beta.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/detect-filetype.js +3 -12
- package/dist/detect-filetype.js.map +1 -1
- package/dist/index.js +52 -90
- package/dist/index.js.map +1 -1
- package/dist/process-image.browser.js +13 -34
- package/dist/process-image.browser.js.map +1 -1
- package/dist/process-image.js +7 -24
- package/dist/process-image.js.map +1 -1
- package/package.json +6 -6
- package/src/detect-filetype.js +8 -9
- package/src/index.js +31 -37
- package/src/process-image.browser.js +77 -69
- package/src/process-image.js +38 -31
- package/test/unit/spec/index.js +58 -59
package/test/unit/spec/index.js
CHANGED
|
@@ -3,11 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {assert} from '@webex/test-helper-chai';
|
|
6
|
-
import {
|
|
7
|
-
readExifData,
|
|
8
|
-
orient,
|
|
9
|
-
updateImageOrientation
|
|
10
|
-
} from '@webex/helper-image';
|
|
6
|
+
import {readExifData, orient, updateImageOrientation} from '@webex/helper-image';
|
|
11
7
|
import fileHelper from '@webex/test-helper-file';
|
|
12
8
|
import sinon from 'sinon';
|
|
13
9
|
import {browserOnly, nodeOnly} from '@webex/test-helper-mocha';
|
|
@@ -17,8 +13,8 @@ describe('helper-image', () => {
|
|
|
17
13
|
xdescribe('readExifData()', () => {
|
|
18
14
|
let buffer;
|
|
19
15
|
|
|
20
|
-
browserOnly(before)(() =>
|
|
21
|
-
.then((resFile) => {
|
|
16
|
+
browserOnly(before)(() =>
|
|
17
|
+
fileHelper.fetch('/Portrait_7.jpg').then((resFile) => {
|
|
22
18
|
/* global FileReader */
|
|
23
19
|
const fileReader = new FileReader();
|
|
24
20
|
|
|
@@ -30,12 +26,14 @@ describe('helper-image', () => {
|
|
|
30
26
|
resolve();
|
|
31
27
|
};
|
|
32
28
|
});
|
|
33
|
-
})
|
|
29
|
+
})
|
|
30
|
+
);
|
|
34
31
|
|
|
35
|
-
nodeOnly(before)(() =>
|
|
36
|
-
.then((resFile) => {
|
|
32
|
+
nodeOnly(before)(() =>
|
|
33
|
+
fileHelper.fetch('/Portrait_7.jpg').then((resFile) => {
|
|
37
34
|
buffer = resFile;
|
|
38
|
-
})
|
|
35
|
+
})
|
|
36
|
+
);
|
|
39
37
|
|
|
40
38
|
it('adds exif orientation information on the image file', () => {
|
|
41
39
|
const sampleFile = {
|
|
@@ -44,17 +42,16 @@ describe('helper-image', () => {
|
|
|
44
42
|
type: 'image/jpeg',
|
|
45
43
|
image: {
|
|
46
44
|
height: 300,
|
|
47
|
-
width: 362
|
|
45
|
+
width: 362,
|
|
48
46
|
},
|
|
49
47
|
mimeType: 'image/jpeg',
|
|
50
|
-
objectType: 'file'
|
|
48
|
+
objectType: 'file',
|
|
51
49
|
};
|
|
52
50
|
|
|
53
|
-
return readExifData(sampleFile, buffer)
|
|
54
|
-
.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
51
|
+
return readExifData(sampleFile, buffer).then((res) => {
|
|
52
|
+
assert.equal(res, buffer);
|
|
53
|
+
assert.equal(sampleFile.orientation, 7);
|
|
54
|
+
});
|
|
58
55
|
});
|
|
59
56
|
|
|
60
57
|
it('adds replaces height/width with exif height/width information', () => {
|
|
@@ -64,47 +61,49 @@ describe('helper-image', () => {
|
|
|
64
61
|
type: 'image/jpeg',
|
|
65
62
|
image: {
|
|
66
63
|
height: 300,
|
|
67
|
-
width: 362
|
|
64
|
+
width: 362,
|
|
68
65
|
},
|
|
69
66
|
mimeType: 'image/jpeg',
|
|
70
|
-
objectType: 'file'
|
|
67
|
+
objectType: 'file',
|
|
71
68
|
};
|
|
72
69
|
|
|
73
|
-
return readExifData(sampleFile, buffer)
|
|
74
|
-
.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
70
|
+
return readExifData(sampleFile, buffer).then((res) => {
|
|
71
|
+
assert.equal(res, buffer);
|
|
72
|
+
assert.equal(sampleFile.orientation, 7);
|
|
73
|
+
assert.equal(sampleFile.exifHeight, 450);
|
|
74
|
+
assert.equal(sampleFile.exifWidth, 600);
|
|
75
|
+
});
|
|
80
76
|
});
|
|
81
77
|
});
|
|
82
78
|
|
|
83
79
|
browserOnly(describe)('updateImageOrientation()', () => {
|
|
84
80
|
let file;
|
|
85
81
|
|
|
86
|
-
before(() =>
|
|
87
|
-
.then((resFile) => {
|
|
82
|
+
before(() =>
|
|
83
|
+
fileHelper.fetch('/Portrait_7.jpg').then((resFile) => {
|
|
88
84
|
file = resFile;
|
|
89
85
|
file.displayName = 'Portrait_7.jpg';
|
|
90
86
|
file.mimeType = 'image/jpeg';
|
|
91
|
-
})
|
|
87
|
+
})
|
|
88
|
+
);
|
|
92
89
|
|
|
93
|
-
it('does not add exif data on image file', () =>
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
it('does not add exif data on image file', () =>
|
|
91
|
+
updateImageOrientation(file, {shouldNotAddExifData: true})
|
|
92
|
+
.then((res) => {
|
|
93
|
+
assert.equal(file.orientation, undefined);
|
|
96
94
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
return fileHelper.isMatchingFile(res, file);
|
|
96
|
+
})
|
|
97
|
+
.then((result) => assert.isTrue(result)));
|
|
100
98
|
|
|
101
|
-
it('adds exif data on the image file', () =>
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
it('adds exif data on the image file', () =>
|
|
100
|
+
updateImageOrientation(file)
|
|
101
|
+
.then((res) => {
|
|
102
|
+
assert.equal(file.orientation, 7);
|
|
104
103
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
return fileHelper.isMatchingFile(res, file);
|
|
105
|
+
})
|
|
106
|
+
.then((result) => assert.isTrue(result)));
|
|
108
107
|
});
|
|
109
108
|
|
|
110
109
|
describe('orient()', () => {
|
|
@@ -114,10 +113,10 @@ describe('helper-image', () => {
|
|
|
114
113
|
type: 'image/jpeg',
|
|
115
114
|
image: {
|
|
116
115
|
height: 300,
|
|
117
|
-
width: 362
|
|
116
|
+
width: 362,
|
|
118
117
|
},
|
|
119
118
|
mimeType: 'image/jpeg',
|
|
120
|
-
objectType: 'file'
|
|
119
|
+
objectType: 'file',
|
|
121
120
|
};
|
|
122
121
|
const options = {
|
|
123
122
|
img: 'Portrait_7.jpg',
|
|
@@ -132,58 +131,56 @@ describe('helper-image', () => {
|
|
|
132
131
|
transform: sinon.stub().returns(() => true),
|
|
133
132
|
scale: sinon.stub().returns(() => true),
|
|
134
133
|
drawImage: sinon.stub().returns(() => true),
|
|
135
|
-
restore: sinon.stub().returns(() => true)
|
|
136
|
-
}
|
|
134
|
+
restore: sinon.stub().returns(() => true),
|
|
135
|
+
},
|
|
137
136
|
};
|
|
138
137
|
const {height, width} = options;
|
|
139
138
|
const events = [
|
|
140
139
|
{
|
|
141
|
-
orientation: 1
|
|
140
|
+
orientation: 1,
|
|
142
141
|
},
|
|
143
142
|
{
|
|
144
143
|
orientation: 2,
|
|
145
144
|
flip: true,
|
|
146
|
-
transform: [-1, 0, 0, 1, width, 0]
|
|
145
|
+
transform: [-1, 0, 0, 1, width, 0],
|
|
147
146
|
},
|
|
148
147
|
{
|
|
149
148
|
orientation: 3,
|
|
150
149
|
rotate: '180',
|
|
151
|
-
transform: [-1, 0, 0, -1, width, height]
|
|
150
|
+
transform: [-1, 0, 0, -1, width, height],
|
|
152
151
|
},
|
|
153
152
|
{
|
|
154
153
|
orientation: 4,
|
|
155
154
|
flip: true,
|
|
156
155
|
rotate: '180',
|
|
157
|
-
transform: [1, 0, 0, -1, 0, height]
|
|
156
|
+
transform: [1, 0, 0, -1, 0, height],
|
|
158
157
|
},
|
|
159
158
|
{
|
|
160
159
|
orientation: 5,
|
|
161
160
|
flip: true,
|
|
162
161
|
rotate: '270',
|
|
163
|
-
transform: [0, 1, 1, 0, 0, 0]
|
|
162
|
+
transform: [0, 1, 1, 0, 0, 0],
|
|
164
163
|
},
|
|
165
164
|
{
|
|
166
165
|
orientation: 6,
|
|
167
166
|
rotate: '270',
|
|
168
|
-
transform: [0, 1, -1, 0, height, 0]
|
|
167
|
+
transform: [0, 1, -1, 0, height, 0],
|
|
169
168
|
},
|
|
170
169
|
{
|
|
171
170
|
orientation: 7,
|
|
172
171
|
flip: true,
|
|
173
172
|
rotate: '90',
|
|
174
|
-
transform: [0, -1, -1, 0, height, width]
|
|
173
|
+
transform: [0, -1, -1, 0, height, width],
|
|
175
174
|
},
|
|
176
175
|
{
|
|
177
176
|
orientation: 8,
|
|
178
177
|
rotate: '90',
|
|
179
|
-
transform: [0, -1, 1, 0, 0, width]
|
|
180
|
-
}
|
|
178
|
+
transform: [0, -1, 1, 0, 0, width],
|
|
179
|
+
},
|
|
181
180
|
];
|
|
182
181
|
|
|
183
182
|
events.forEach((def) => {
|
|
184
|
-
const {
|
|
185
|
-
flip, orientation, rotate, transform
|
|
186
|
-
} = def;
|
|
183
|
+
const {flip, orientation, rotate, transform} = def;
|
|
187
184
|
|
|
188
185
|
describe(`when an image file is received with orientation as ${orientation}`, () => {
|
|
189
186
|
options.orientation = orientation;
|
|
@@ -197,7 +194,9 @@ describe('helper-image', () => {
|
|
|
197
194
|
if (transform) {
|
|
198
195
|
assert.isTrue(options.ctx.transform.calledWith(...transform));
|
|
199
196
|
}
|
|
200
|
-
assert.isTrue(
|
|
197
|
+
assert.isTrue(
|
|
198
|
+
options.ctx.drawImage.calledWith(options.img, options.x, options.y, width, height)
|
|
199
|
+
);
|
|
201
200
|
});
|
|
202
201
|
});
|
|
203
202
|
});
|