express middleware to simulate fastly cdn


Keywords
express, imageopto, fastly, cdn, compression
License
MIT
Install
npm install hastily@0.4.1

Documentation

hastily

npm downloads CircleCI codecov snyk peer dependency npm downloads

Drop-in compatible Express middleware to replicate the Fastly Image Optimization API

Usage

The middleware works a lot like compression, a standard Express middleware which transparently compresses any text-based response body that emits from something in the middleware chain.

So hastily works as an add-on to an Express server or middleware that is already serving images.

import express, { static } from 'express';
import { imageopto } from 'hastily';

const app = express();
app.use('/images', imageopto(), static('/www/images'));

app.listen(8000);

You now have an app which can serve any image from /www/images, and optimize it with URL parameters from the Fastly Image Optimization API.

Full API doc at zetlen.github.io/hastily

TODO

  • implement resize and crop mappers
  • throw on unsupported
  • implement enable and disable for upscaling in resize
  • implement format, auto=webp, and quality params in post-manip phase
  • add unit tests
  • add image-diff automated testing
  • implement sharpen, mapping [amt, radius, threshold] to libvips sharpen params
  • implement brightness, contrast, saturation by figuring out percentage to multiplier mapping
  • use image.metadata() to implement relative and context-based methods
  • add header-based methods
    • montage
    • overlay