This repository was archived by the owner on Jul 26, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +7
-7
lines changed Expand file tree Collapse file tree 3 files changed +7
-7
lines changed Original file line number Diff line number Diff line change 43
43
},
44
44
"homepage" : " https://github.com/image-js/image-js#readme" ,
45
45
"dependencies" : {
46
+ "@jsonjoy.com/base64" : " ^1.1.2" ,
46
47
"bresenham-zingl" : " ^0.2.0" ,
47
48
"colord" : " ^2.9.3" ,
48
49
"fast-bmp" : " ^2.0.1" ,
Original file line number Diff line number Diff line change @@ -2,6 +2,9 @@ import { createRgbaImage } from '../../../test/testUtils.js';
2
2
import { encode } from '../encode.js' ;
3
3
import { encodeBase64 } from '../encodeBase64.js' ;
4
4
5
+ /**
6
+ * @vitest -environment jsdom
7
+ */
5
8
test ( 'basic image (png)' , ( ) => {
6
9
const image = testUtils . createGreyImage ( [
7
10
[ 0 , 0 , 0 , 0 , 0 ] ,
Original file line number Diff line number Diff line change
1
+ import { toBase64 } from '@jsonjoy.com/base64' ;
2
+
1
3
import type { Image } from '../Image.js' ;
2
4
3
5
import { encode } from './encode.js' ;
4
6
import type { ImageFormat } from './encode.js' ;
5
-
6
7
/**
7
8
* Converts image into a base64 URL string.
8
9
* @param image - Image to get base64 encoding from.
@@ -11,12 +12,7 @@ import type { ImageFormat } from './encode.js';
11
12
*/
12
13
export function encodeBase64 ( image : Image , format : ImageFormat ) {
13
14
const buffer = encode ( image , { format } ) ;
14
- const binaryArray = [ ] ;
15
- for ( const el of buffer ) {
16
- binaryArray . push ( String . fromCodePoint ( el ) ) ;
17
- }
18
- const binaryString = binaryArray . join ( '' ) ;
19
- const base64String = btoa ( binaryString ) ;
15
+ const base64String = toBase64 ( buffer ) ;
20
16
const dataURL = `data:image/${ format } ;base64,${ base64String } ` ;
21
17
return dataURL ;
22
18
}
You can’t perform that action at this time.
0 commit comments