Skip to content

Instantly share code, notes, and snippets.

@benfoxall
Created January 16, 2021 17:14
Show Gist options
  • Save benfoxall/47a8ce7ed12b14e79dffa1048e2c2fa7 to your computer and use it in GitHub Desktop.
Save benfoxall/47a8ce7ed12b14e79dffa1048e2c2fa7 to your computer and use it in GitHub Desktop.
Find the size of a gif by requesting only 4 bytes
await gifsize('https://media.giphy.com/media/3ornjZLITGcFQVRbxK/source.gif')
// > {width: 500, height: 247}
async function gifsize (url) {
const result = await fetch(url, {headers: {Range: 'bytes=6-9'}})
const [width, height] = new Uint16Array(await result.arrayBuffer())
return {width, height}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment