npm

Need private packages and team management tools?Check out npm Orgs. »

slicica

9.0.1 • Public • Published

slicica npm version Dependency Status

diminutive for image in croatian

Streaming image serving/resizing Connect middleware using sharp / libvips.

Intended for usage behind a proxy cache (e.g. nginx, varnish) or a CDN (e.g. CloudFlare) as it doesn't cache results on its own.

Install

npm i -S slicica

Installing this module will automatically fetch and build libvips and its dependencies on Linux, MacOS and Windows x64.

For more information read sharp's documentation.

Usage

app.use(require('slicica')(options))
const app = express()
const slicica = require('slicica')
 
app.use(slicica(
  // default options below
  {
    prefix: '/', // url prefix on which to serve the images
    root: '', // root folder / prefix to prepend to the requested image (path where the images reside)
    maxAge: 0, // takes seconds as integer | ms compatible string | false to disable
    etag: true, // generate and send ETag header
    lastModified: true, // send the Last-Modified header
    progressive: false, // progressive scan for JPG and PNG
    quality: 80, // output quality for jpeg, webp and tiff
    compression: 6, // image compression level (0-9)
    contentTypes: [
      'image/gif'
      'image/jpeg'
      'image/png'
      'image/svg+xml'
      'image/webp'
    ], // content types to serve (text types like svg+xml are just piped through), other requests are ignored
    cache: false, // options passed to sharp.cache
    concurrency: 0 // number of threads sharp will use (0 = number of cores)
  }
))

Request example

http://localhost:####/images/random.jpg?w=800
http://localhost:####/images/random.jpg?h=600
http://localhost:####/images/random.jpg?w=300&h=200&g=north
// width
// height
= 'center' // gravity (north|northeast|east|southeast|south|southwest|west|northwest|center|centre)
if (&& h) {
  // crops to exact dimensions using the default or specified gravity
} else if (|| h) {
  // resizes preserving the aspect ratio
} else {
  // just pipes the original image as response
}

License

MIT © Stipe Kotarac (https://github.com/kotarac)

install

npm i slicica

Downloadsweekly downloads

6

version

9.0.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability