Skip to content

Instantly share code, notes, and snippets.

@sspencer
Created October 31, 2010 22:27
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save sspencer/657246 to your computer and use it in GitHub Desktop.
Save sspencer/657246 to your computer and use it in GitHub Desktop.
Serve a transparent GIF from NodeJS
// 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);
@elhardoum
Copy link

elhardoum commented Feb 14, 2022

@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

@jjolmo
Copy link

jjolmo commented Nov 23, 2023

@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