diff options
author | Stephen Whitmore <sww@eight45.net> | 2017-06-06 11:32:38 -0700 |
---|---|---|
committer | Stephen Whitmore <sww@eight45.net> | 2017-06-06 11:32:38 -0700 |
commit | b4070f9b60e49b2c378bd85b4d0834101eae2632 (patch) | |
tree | 53fb25e01e16b31b3d3903895d2a84194e0e9f1d /lib | |
parent | ae9162cbf72e851a7349aa0579ba695bfa9be6b5 (diff) | |
download | patchfoo-b4070f9b60e49b2c378bd85b4d0834101eae2632.tar.gz patchfoo-b4070f9b60e49b2c378bd85b4d0834101eae2632.zip |
Use JPEG EXIF data to rotate image blobs.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/serve.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/serve.js b/lib/serve.js index 9d5eb82..81ab0b7 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -20,6 +20,7 @@ var ident = require('pull-identify-filetype') var htime = require('human-time') var ph = require('pull-hyperscript') var emojis = require('emoji-named-characters') +var jpeg = require('jpeg-autorotate') module.exports = Serve @@ -954,10 +955,20 @@ Serve.prototype.blob = function (id) { else return self.respond(500, err.message || err) } if (!has) return self.respond(404, 'Not found') + blobs.size(id, done()) + var rotatedSize = null + pull( blobs.get(id), pull.map(Buffer), + pull.asyncMap(function (buf, cb) { + jpeg.rotate(buf, {}, function (err, buffer, orientation) { + if (err) return cb(null, buf) + rotatedSize = buffer.length + return cb(null, buffer) + }) + }), ident(done().bind(self, null)), self.respondSink() ) @@ -965,7 +976,7 @@ Serve.prototype.blob = function (id) { if (err) console.trace(err) type = type && mime.lookup(type) if (type) self.res.setHeader('Content-Type', type) - if (typeof size === 'number') self.res.setHeader('Content-Length', size) + if (typeof size === 'number') self.res.setHeader('Content-Length', rotatedSize || size) if (self.query.name) self.res.setHeader('Content-Disposition', 'inline; filename='+encodeDispositionFilename(self.query.name)) self.res.setHeader('Cache-Control', 'public, max-age=315360000') |