Untitled

mail@pastecode.io avatar
unknown
javascript
7 months ago
610 B
2
Indexable
Never
// 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);
Leave a Comment