Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ad-si/image-resize-middleware
Image resizing middleware
https://github.com/ad-si/image-resize-middleware
express expressjs graphicsmagick middleware
Last synced: 20 days ago
JSON representation
Image resizing middleware
- Host: GitHub
- URL: https://github.com/ad-si/image-resize-middleware
- Owner: ad-si
- Created: 2015-08-17T20:49:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-09T20:33:04.000Z (almost 9 years ago)
- Last Synced: 2024-10-12T13:51:54.045Z (about 1 month ago)
- Topics: express, expressjs, graphicsmagick, middleware
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Image Resizer
GraphicsMagick powered, multi threaded image resizing middleware.
## Installation
```sh
npm install --save image-resize-middleware
```## Usage
```js
const path = require('path')
const express = require('express')
const imageResizer = require('image-resize-middleware')
const port = 3000
const publicDirectory = path.join(__dirname, 'public')const app = express()
app.use(imageResizer.getMiddleware({
basePath: path.join(publicDirectory, 'images'),
thumbnailsPath: path.join(publicDirectory, 'thumbnails'),
}))
app.use(express.static(publicDirectory))app.listen(
port,
() => console.log('Listening on http://localhost:' + port)
)
```Every request for an image at `/images///`
which also contains a width, height, max-width or max-height query parameter
will be scaled to the specified value.For example a request for
`http://localhost:3000/images/test.png?max-width=50&max-height=50`
triggers the creation of a proportionally scaled thumbnail
with a maximum bounding box of 50px by 50px.
It is saved at `$(pwd)/public/thumbnails/test_50x50>.png`
and responded to the request.## Algorithm
All images to be scaled are added to a queue.
The queue is worked off with one worker per core.