Middleware to process images with sharp converter
Last updated 2 years ago by naumovs .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install @naumovs/image-middleware-sharp 
SYNC missed versions from official npm registry.


Express/Connect middleware to transform images on-demand.


  // Root path to the folder with original images
  root: 'public',
  // Root path to the folder with cached images
  cache: 'public',

  // list of transforms that are available
  transforms: {
    test(stream, sharp) {
      return stream

  // prefix for your transforms in the url
  prefix: 't_',

Given configuration above and the file available in public/uploads/file.png you will be able to access the transformed file with one of following requests

GET /uploads/t_test/file.png
GET /uploads/t_test/file.png.webp
HEAD /uploads/t_test/file.png
HEAD /uploads/t_test/file.png.webp

After first access a new file will be generated in cache folder at requested path. Next time it will serve cached file. If you want to omit cache add ?nocache to the url

Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (4)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |