Skip to content

Instantly share code, notes, and snippets.

@ngryman
Created June 24, 2018 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngryman/75229b0956cd1bc51fdd4055fbe218e4 to your computer and use it in GitHub Desktop.
Save ngryman/75229b0956cd1bc51fdd4055fbe218e4 to your computer and use it in GitHub Desktop.
Keep the aspect ratio of your images using GIFs
function createGif(width, height) {
const buffer = new ArrayBuffer(24)
const byteView = new Uint8Array(buffer)
// signature
byteView.set([ 71, 73, 70, 56, 57, 97 ], 0)
// size
byteView.set([width, width >> 8], 6)
byteView.set([height, height >> 8], 8)
// jibber jabber
byteView.set([44], 13)
byteView.set([1], 18)
byteView.set([1], 20)
byteView.set([2], 23)
return btoa(String.fromCharCode.apply(null, byteView))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment