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 4343 },
4444 "homepage" : " https://github.com/image-js/image-js#readme" ,
4545 "dependencies" : {
46+ "@jsonjoy.com/base64" : " ^1.1.2" ,
4647 "bresenham-zingl" : " ^0.2.0" ,
4748 "colord" : " ^2.9.3" ,
4849 "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';
22import { encode } from '../encode.js' ;
33import { encodeBase64 } from '../encodeBase64.js' ;
44
5+ /**
6+ * @vitest -environment jsdom
7+ */
58test ( 'basic image (png)' , ( ) => {
69 const image = testUtils . createGreyImage ( [
710 [ 0 , 0 , 0 , 0 , 0 ] ,
Original file line number Diff line number Diff line change 1+ import { toBase64 } from '@jsonjoy.com/base64' ;
2+
13import type { Image } from '../Image.js' ;
24
35import { encode } from './encode.js' ;
46import type { ImageFormat } from './encode.js' ;
5-
67/**
78 * Converts image into a base64 URL string.
89 * @param image - Image to get base64 encoding from.
@@ -11,12 +12,7 @@ import type { ImageFormat } from './encode.js';
1112 */
1213export function encodeBase64 ( image : Image , format : ImageFormat ) {
1314 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 ) ;
2016 const dataURL = `data:image/${ format } ;base64,${ base64String } ` ;
2117 return dataURL ;
2218}
You can’t perform that action at this time.
0 commit comments