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-
21import { createRgbaImage } from '../../../test/testUtils.js' ;
32import { encode } from '../encode.js' ;
43import { encodeBase64 } from '../encodeBase64.js' ;
5- /**
6- * @vitest -environment jsdom
7- */
4+
85test ( 'basic image (png)' , ( ) => {
96 const image = testUtils . createGreyImage ( [
107 [ 0 , 0 , 0 , 0 , 0 ] ,
@@ -86,6 +83,3 @@ test('legacy image-js test', () => {
8683 expect ( typeof url ) . toBe ( 'string' ) ;
8784 expect ( base64Data ) . toBe ( url . slice ( url . indexOf ( ',' ) + 1 ) ) ;
8885} ) ;
89-
90-
91-
Original file line number Diff line number Diff line change @@ -10,9 +10,11 @@ import type { ImageFormat } from './encode.js';
1010 * @returns base64 string.
1111 */
1212export 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+ ) ;
1817
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