Middleware that processes images according to the query string. It is intended to be used in a development setting with the static middleware, but should play well with any middleware further down the stack, even an http proxy, via hijackresponse.
Images are processed using the impro module which implements automatic switching between a number of image libraries based on the requested options.
Important note: This module is intended for development. While impro validates requested image operations, ultimately image data which could be untrusted in such use would be passed directly to various command line tools. In addition, extremely large images represent an attack surface unless restrictions on maximum input and output sizes are configured.
Make sure you have node.js and npm installed, then run:
npm install express-processimage
express-processimage
supports pngcrush
, pngquant
, optipng
,
jpegtran
, inkscape
, svgfilter
,
and all methods listed under "manipulation" and "drawing primitives"
in the documentation
for the gm module.
Multiple tools can be applied to the same image (separated by &
, and
the order is significant). Arguments for the individual tools are
separated by non-URL encoded comma or plus.
http://localhost:1337/myImage.png?pngcrush=-rem,alla
http://localhost:1337/myImage.png?pngcrush=-rem+alla
http://localhost:1337/myImage.png?optipng=-o7
http://localhost:1337/bigImage.png?resize=400,300&pngquant=128&pngcrush
http://localhost:1337/hello.png?setFormat=gif
http://localhost:1337/logo.svg?inkscape
http://localhost:1337/file.svg?svgfilter=--runScript=makeItBlue.js
Express 3.0 syntax:
var express = require('express'),
processImage = require('express-processimage'),
root = '/path/to/my/static/files';
express()
.use(processImage({ root: root }))
.use(express.static(root))
.listen(1337);
From this point forward, the resposnes tp GET requests to port 1337 are matched by their Content-Type matched and in the case of an it will be processed by the image pipeline using options specified in query string. The processed output is delivered to the client.