@@ -27,8 +27,12 @@ const EXIF_FILES = [
27
27
. map ( ( fileName , i ) => fileName . replace ( '#' , i % 9 ) )
28
28
. map ( ( fileName ) => path . join ( IMAGE_DIR , 'Exif orientation examples' , fileName ) )
29
29
. map ( ( filePath ) => fs . readFileSync ( filePath ) ) ;
30
+ const BMP_NAME = 'sample_1280×853.bmp' ;
31
+ const BMP_PATH = path . join ( IMAGE_DIR , BMP_NAME ) ;
32
+ const BMP_FILE = fs . readFileSync ( BMP_PATH ) ;
30
33
const base64String = `data:image/jpeg;base64,${ Buffer . from ( JPG_FILE ) . toString ( 'base64' ) } ` ;
31
34
const base64String2 = `data:image/png;base64,${ Buffer . from ( PNG_FILE ) . toString ( 'base64' ) } ` ;
35
+ const base64String3 = `data:image/bmp;base64,${ Buffer . from ( BMP_FILE ) . toString ( 'base64' ) } ` ;
32
36
33
37
chai . use ( chaiAsPromised ) ;
34
38
@@ -68,6 +72,19 @@ describe('Tests', function () {
68
72
expect ( base64 ) . to . equal ( base64String2 ) ;
69
73
} ) ;
70
74
75
+ it ( 'get File from bmp base64' , async ( ) => {
76
+ const file = await getFilefromDataUrl ( base64String3 , BMP_PATH ) ;
77
+ expect ( file . type ) . to . equal ( 'image/bmp' ) ;
78
+ expect ( file . size ) . to . equal ( 3275658 ) ;
79
+ expect ( file ) . to . be . an . instanceof ( Blob ) ;
80
+ } ) ;
81
+
82
+ it ( 'get base64 from bmp file' , async ( ) => {
83
+ const file = new File ( [ BMP_FILE ] , BMP_NAME , { type : 'image/bmp' } ) ;
84
+ const base64 = await getDataUrlFromFile ( file ) ;
85
+ expect ( base64 ) . to . equal ( base64String3 ) ;
86
+ } ) ;
87
+
71
88
it ( 'load image' , async ( ) => {
72
89
const img = await loadImage ( base64String ) ;
73
90
expect ( img ) . to . be . an . instanceof ( Image ) ;
@@ -187,6 +204,50 @@ describe('Tests', function () {
187
204
expect ( img . height ) . to . be . at . most ( maxWidthOrHeight ) ;
188
205
} ) ;
189
206
207
+ it ( 'compress bmp image file' , async ( ) => {
208
+ const file = new File ( [ BMP_FILE ] , BMP_NAME , { type : 'image/bmp' } ) ;
209
+
210
+ const maxSizeMB = 1 ;
211
+ const maxSizeByte = maxSizeMB * 1024 * 1024 ;
212
+
213
+ const compressedFile = await imageCompression ( file , { maxSizeMB, useWebWorker : false , exifOrientation : - 2 , maxIteration : 15 } ) ;
214
+ expect ( compressedFile . size ) . to . be . at . most ( maxSizeByte ) ;
215
+ } ) ;
216
+
217
+ it ( 'resize bmp image file' , async ( ) => {
218
+ const file = new File ( [ BMP_FILE ] , BMP_NAME , { type : 'image/bmp' } ) ;
219
+
220
+ const maxWidthOrHeight = 720 ;
221
+
222
+ const compressedFile = await imageCompression ( file , { maxWidthOrHeight, useWebWorker : false , exifOrientation : - 2 } ) ;
223
+
224
+ const temp = await drawFileInCanvas ( compressedFile ) ;
225
+ const img = temp [ 0 ] ;
226
+ expect ( img . width ) . to . be . at . most ( maxWidthOrHeight ) ;
227
+ expect ( img . height ) . to . be . at . most ( maxWidthOrHeight ) ;
228
+ } ) ;
229
+
230
+ it ( 'compress and resize bmp image file' , async ( ) => {
231
+ const file = new File ( [ BMP_FILE ] , BMP_NAME , { type : 'image/bmp' } ) ;
232
+
233
+ const maxSizeMB = 1 ;
234
+ const maxSizeByte = maxSizeMB * 1024 * 1024 ;
235
+ const maxWidthOrHeight = 720 ;
236
+
237
+ const compressedFile = await imageCompression ( file , {
238
+ maxSizeMB,
239
+ maxWidthOrHeight,
240
+ useWebWorker : false ,
241
+ } ) ;
242
+
243
+ expect ( compressedFile . size ) . to . be . at . most ( maxSizeByte ) ;
244
+
245
+ const temp = await drawFileInCanvas ( compressedFile ) ;
246
+ const img = temp [ 0 ] ;
247
+ expect ( img . width ) . to . be . at . most ( maxWidthOrHeight ) ;
248
+ expect ( img . height ) . to . be . at . most ( maxWidthOrHeight ) ;
249
+ } ) ;
250
+
190
251
it ( 'fails if wrong file provided' , async ( ) => {
191
252
const file = undefined ;
192
253
0 commit comments