Skip to content

Instantly share code, notes, and snippets.

blah
@mikey0000
mikey0000 / convertToJPG
Last active March 15, 2024 10:10
convert png to jpeg using javascript and write back to original file
function convertDataURIToBinary(dataURI) {
var BASE64_MARKER = ';base64,';
var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
var base64 = dataURI.substring(base64Index);
var raw = window.atob(base64);
var rawLength = raw.length;
var array = new Uint8Array(new ArrayBuffer(rawLength));
for (i = 0; i < rawLength; i++) {
array[i] = raw.charCodeAt(i);