Untitled
unknown
javascript
2 years ago
610 B
8
Indexable
// Function to fetch image bytes
async function fetchImageBytes(url) {
try {
const response = await fetch(url);
const arrayBuffer = await response.arrayBuffer();
// Convert the ArrayBuffer to a Uint8Array
const uint8Array = new Uint8Array(arrayBuffer);
// You now have the image bytes in the uint8Array
console.log(uint8Array);
return uint8Array;
} catch (error) {
console.error('Error fetching image:', error);
}
}
// Image URL
const imageUrl = 'https://imgur.com/IEh1oMf';
// Call the function with the image URL
fetchImageBytes(imageUrl);Editor is loading...
Leave a Comment