Skip to content

Commit 5d3ba91

Browse files
committed
fix: get more reliable algo version
1 parent 8a3792f commit 5d3ba91

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/save/encodeBase64.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import type { ImageFormat } from './encode.js';
1111
*/
1212
export function encodeBase64(image: Image, format: ImageFormat) {
1313
const buffer = encode(image, { format });
14-
const binaryString = new TextDecoder('latin1').decode(
15-
Uint8Array.from(buffer),
16-
);
17-
14+
const binaryArray = [];
15+
for (const el of buffer) {
16+
binaryArray.push(String.fromCodePoint(el));
17+
}
18+
const binaryString = binaryArray.join('');
1819
const base64String = btoa(binaryString);
19-
return `data:image/${format};base64,${base64String}`;
20+
const dataURL = `data:image/${format};base64,${base64String}`;
21+
return dataURL;
2022
}

0 commit comments

Comments
 (0)