This repository was archived by the owner on Jul 26, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +8
-12
lines changed Expand file tree Collapse file tree 2 files changed +8
-12
lines changed Original file line number Diff line number Diff line change 1
-
2
1
import { createRgbaImage } from '../../../test/testUtils.js' ;
3
2
import { encode } from '../encode.js' ;
4
3
import { encodeBase64 } from '../encodeBase64.js' ;
5
- /**
6
- * @vitest -environment jsdom
7
- */
4
+
8
5
test ( 'basic image (png)' , ( ) => {
9
6
const image = testUtils . createGreyImage ( [
10
7
[ 0 , 0 , 0 , 0 , 0 ] ,
@@ -86,6 +83,3 @@ test('legacy image-js test', () => {
86
83
expect ( typeof url ) . toBe ( 'string' ) ;
87
84
expect ( base64Data ) . toBe ( url . slice ( url . indexOf ( ',' ) + 1 ) ) ;
88
85
} ) ;
89
-
90
-
91
-
Original file line number Diff line number Diff line change @@ -10,9 +10,11 @@ import type { ImageFormat } from './encode.js';
10
10
* @returns base64 string.
11
11
*/
12
12
export function encodeBase64 ( image : Image , format : ImageFormat ) {
13
- const buffer = encode ( image , { format } ) ;
14
- const binaryString = new TextDecoder ( 'latin1' ) . decode ( Uint8Array . from ( buffer ) ) ;
15
- const base64String = btoa ( binaryString ) ;
16
- return `data:image/${ format } ;base64,${ base64String } ` ;
17
- }
13
+ const buffer = encode ( image , { format } ) ;
14
+ const binaryString = new TextDecoder ( 'latin1' ) . decode (
15
+ Uint8Array . from ( buffer ) ,
16
+ ) ;
18
17
18
+ const base64String = btoa ( binaryString ) ;
19
+ return `data:image/${ format } ;base64,${ base64String } ` ;
20
+ }
You can’t perform that action at this time.
0 commit comments