Created
January 16, 2021 17:14
-
-
Save benfoxall/47a8ce7ed12b14e79dffa1048e2c2fa7 to your computer and use it in GitHub Desktop.
Find the size of a gif by requesting only 4 bytes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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