Created
June 24, 2018 12:54
-
-
Save ngryman/75229b0956cd1bc51fdd4055fbe218e4 to your computer and use it in GitHub Desktop.
Keep the aspect ratio of your images using GIFs
This file contains 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
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