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

@naumovs/image-middleware-sharp

Express/Connect middleware to transform images on-demand.

Usage

app.use(resizer({
  // 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
        .resize(200)
        .normalise()
        .crop();
    }
  }

  // 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)
Downloads
Today 0
This Week 2
This Month 2
Last Day 0
Last Week 0
Last Month 6
Dependencies (6)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |