Skip to content

Instantly share code, notes, and snippets.

@vodolaz095
Last active December 8, 2015 20:10
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 vodolaz095/efe3d462f0c700f01b0d to your computer and use it in GitHub Desktop.
Save vodolaz095/efe3d462f0c700f01b0d to your computer and use it in GitHub Desktop.
Render 1 pixel jpg image using expressjs
'use strict';
var express = require('express');
var app = express();
app.get('/1pixel.jpg', function(req,res){
var
hex1pixeljpeg = 'ffd8ffe000104a46494600010101006000600000ffe1001645786966000049492a0008000000000000000000ffdb00430001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101ffdb00430101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101ffc00011080001000103012200021101031101ffc400150001010000000000000000000000000000000affc40014100100000000000000000000000000000000ffc40014010100000000000000000000000000000000ffc40014110100000000000000000000000000000000ffda000c03010002110311003f00bf8001ffd9',
buffer1PixelJpeg = new Buffer(hex1pixeljpeg, 'hex');
res
.set({
'Content-Type': 'image/jpeg',
'Content-Length': buffer1PixelJpeg.length
}) //http://expressjs.com/en/4x/api.html#res.set
.end(buffer1PixelJpeg,'binary');
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment