express-processimage

raw JSON →
11.2.0 verified Sat Apr 25 auth: no javascript

Express middleware for on-the-fly image processing based on query string parameters. Version 11.2.0. Intended for development use, not production. Supports multiple image formats (PNG, JPG, GIF, SVG) and operations (resize, pngcrush, optipng, jpegtran, svgfilter, etc.). Uses impro module to switch between backends (GraphicsMagick, ImageMagick, command-line tools). Alternative to separate build tools. Note: due to shelling out to external binaries, it presents security concerns; validate inputs and limit image sizes in production.

error Error: spawn optipng ENOENT
cause optipng binary not installed
fix
Install optipng via package manager (e.g., apt-get install optipng).
error TypeError: processImage is not a function
cause Imported incorrectly (named instead of default)
fix
Use const processImage = require('express-processimage') or import processImage from 'express-processimage'.
error Error: Cannot find module 'impro'
cause Missing dependency
fix
Run npm install express-processimage to install all dependencies.
error 403 Forbidden: no root set
cause Root option not provided
fix
Add { root: '/path/to/images' } to processImage options.
breaking Express 4.x requires app.use, not express().use()
fix Use const app = express(); app.use(processImage({root})); app.listen(1337);
deprecated Option 'root' has been required since v5.0.0
fix Always pass { root: '/path' } object.
gotcha Middleware must be placed before express.static to intercept images
fix Order: app.use(processImage({root})), then app.use(express.static(root)).
deprecated Query string tool names changed: 'optipng' deprecated in favor of 'pngcrush'
fix Use 'pngcrush' instead of 'optipng'.
breaking Support for Node.js <10 removed in v8.0.0
fix Upgrade Node.js to v10 or higher.
gotcha ETag modification can cause caching issues with CDN
fix Set cache-control headers explicitly.
npm install express-processimage
yarn add express-processimage
pnpm add express-processimage

Set up Express server with express-processimage middleware to serve processed images via query parameters.

import express from 'express';
import processImage from 'express-processimage';
const app = express();
const root = '/path/to/images';
app.use(processImage({ root }));
app.use(express.static(root));
app.listen(3000);