0.4.0 • Published 7 years ago
webp-middleware v0.4.0
WebP Express Middleware
Inspired by a post from Cloudinary, this middleware generates and delivers JPG-, PNG- and TIFF-images on the fly as WebP-images if the requesting client supports that format.
WebP is a new image format from Google that provides lossless and lossy compression for images on the web. For more information please read the official documentation or the article on html5rocks.com about image compression.
Installation
npm install webp-middlewareUsage
var http = require('http');
var express = require('express');
var webp = require('webp-middleware');
var app = express();
app.use(webp(__dirname + '/public', { ... }));
app.use(express.static(__dirname + '/public'));It is important to insert the webp middleware before the express.static middleware.
First parameter is the path of the static folder.
Second parameter is an optional options object.
You can also have a look into the example folder for examples.
Options
cacheDiris the directory where the webp files are saved. Default is a folder webp-cache in the executing directory (path.join(process.cwd(), 'webp-cache'))presetdelegates to the-presetoption at cwebpqualitydelegates to the-qoption at cwebpalphaQualitydelegates to the-alpha_qoption at cwebpmethoddelegates to the-moption at cwebpsegmentsdelegates to the-segmentsoption at cwebpbytesdelegates to the-sizeoption at cwebppsnrdelegates to the-psnroption at cwebpsizedelegates to the-soption at cwebp. Should be an object withwidthandheightkeysspatialNoiseShapingdelegates to the-snsoption at cwebpfilterdelegates to the-foption at cwebpstrongdelegates to the-strongoption at cwebp. Should be a boolean valuenoStrongdelegates to the-nostrongoption at cwebp. Should be a boolean valuepartitionLimitdelegates to the-partition_limitoption at cwebppassdelegates to the-passoption at cwebpcropdelegates to the-cropoption at cwebp. Should be an object withwidth,height,xandykeysresizedelegates to the-resizeoption at cwebp. Should be an object withwidthandheightkeysmultiThreadingdelegates to the-mtoption at cwebp. Should be a boolean valuelowMemorydelegates to the-low_memoryoption at cwebp. Should be a boolean valuealphaMethoddelegates to the-alpha_methodoption at cwebpalphaCleanupdelegates to the-alpha_cleanupoption at cwebp. Should be a boolean valuenoAlphadelegates to the-noalphaoption at cwebp. Should be a boolean valuelosslessdelegates to the-losslessoption at cwebp. Should be a boolean valuehintdelegates to the-hintoption at cwebpmetadatadelegates to the-metadataoption at cwebp
License
Licensed under the MIT License.