Skip to content

Commit

Permalink
Corrected exif code
Browse files Browse the repository at this point in the history
  • Loading branch information
pdr0663 committed May 1, 2024
1 parent 710d22c commit a89711a
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,17 @@ <h1>Photo Capture</h1>
}
fileName += '.jpg'; // Use JPEG format for better EXIF support

// Modify EXIF data
const base64Image = imageData.replace(/^data:image\/(jpeg|png);base64,/, '');
const exifData = EXIF.readFromBinaryFile(base64ToArrayBuffer(base64Image));
exifData.UserComment = JSON.stringify({
title: title || '',
description: description || ''
// Read EXIF data from the image
EXIF.getData(blob, function() {
// Modify EXIF data
this.UserComment = JSON.stringify({
title: title || '',
description: description || ''
});

// Save the Blob using FileSaver.js
saveAs(blob, fileName);
});

// Create a new Blob with the modified EXIF data
const blobWithExif = new Blob([base64ToArrayBuffer(base64Image)], { type: 'image/jpeg' });
EXIF.setXMPData(blobWithExif, EXIF.serialize(exifData));

// Save the Blob using FileSaver.js
saveAs(blobWithExif, fileName);
}

function base64ToArrayBuffer(base64) {
const binaryString = window.atob(base64);
const len = binaryString.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes.buffer;
}
</script>
</body>
Expand Down

0 comments on commit a89711a

Please sign in to comment.