Created
October 31, 2010 22:27
-
-
Save sspencer/657246 to your computer and use it in GitHub Desktop.
Serve a transparent GIF from NodeJS
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
// Two ways to serve transparent GIF | |
var buf = new Buffer([ | |
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, | |
0x80, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x2c, | |
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, | |
0x02, 0x44, 0x01, 0x00, 0x3b]); | |
res.send(buf, { 'Content-Type': 'image/gif' }, 200); | |
// --- OR ---- | |
var buf = new Buffer(35); | |
buf.write("R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=", "base64"); | |
res.send(buf, { 'Content-Type': 'image/gif' }, 200); |
@chrisspiegl my bad, didn't pay close attention - the image is shown on a website not the standard chrome image viewer page. I'll improve my answer, ty
@chrisspiegl solution worked like a charm. Displays perfectly transparent. Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@elhardoum Not sure where you got these from. I don't see those stylings in the most recent version of Chrome
98.0.4758.80
.When I inspect the
img
element they don't show up (even when ticking theShow all
checkbox).But the 35 byte one shows up as a white pixel and the 43 byte one is transparent and invisible on a black background.