Skip to content

Latest commit

 

History

History
41 lines (33 loc) · 1021 Bytes

README.md

File metadata and controls

41 lines (33 loc) · 1021 Bytes

Dynamic Image Endpoint

npm

Small Express endpoint to serve static images with dynamic sizes. Simply plug the provided handler function into an Express app endpoint and you're good to go.

Installation

yarn add dynamic-image-endpoint
# OR
npm install dynamic-image-endpoint

Usage

import express from 'express';
import handler from 'dynamic-image-endpoint';

const app = express();
app.get('*', handler('path/to/images'));
app.listen(3000);

Now localhost:3000/image.jpg will serve path/to/images/image.jpg. You can additionally specify a width through the query parameters, e.g. localhost:3000/image.jpg?width=200 will serve path/to/images/image.jpg resized to 200px width, the height will be calculated automatically. The resulting image will be saved on disk.

Development

# Setup
yarn

# Build project
yarn build

# Test project
yarn test

# Lint project
yarn lint