npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-middleware-image

v0.0.4

Published

Express middleware to resize pictures from url parameters

Readme

Express Middleware Image


This module is an expressejs middleware to create picture thumbnails.

Install

npm install installs imagemagick wrapper, so you need to install imagemagick binaries too.

OSX

Brew make things really simple

# brew update
# brew install imagemagick
... wait your beer
Linux

You can build from source or ask google.

Usage

This is a very basic bootstrap

var express = require('express')
	, emi = require('express-middleware-image')
	, app = express()

app.configure(function(){
	app.set('port', process.env.PORT || 3000);
	app.use(express.logger('dev'));
	app.use(emi({
		// check options bellow
	}));
});

http.createServer(app).listen(app.get('port'), function () {
	console.log("Express server listening on port " + app.get('port'));
});

Options

— root (required)

the folder containing source pictures (absolute path)

— cache (required)

this folder stores cache data, if this folder does not exists, it will be created with the first generation

— ttl (default 1 day)

max-age header sent to brower in seconds.

— cacheTTL (default 1 day)

time to serve cached version in seconds. To totally disable cache, use 0.

— allowedExtensions (default ['gif', 'png', 'jpg'])

array of extension allowed. Used in the regexp to check if the request could be handled.

— quality (default 80)

jpeg files compression factor, from 1 (light but ugly) to 100 (max but heavy) This parameter is overwriten if q: url parameter is used. This could be used to define a global default quality value for all request.

Scheme

Image generation are request url based. All you need is to call this URL:

http://localhost:3000/key:val[,key2:val2]/path/to/file.jpg

You can add more keys. Ex: 300px height and a very poor quality:

http://localhost:3000/h:300,q:10/path/to/file.jpg

Keys

— h (=height)

Define the Height of the picture, respect the ratio

— w (=width)

Same behaviour as h but set the width

— s (=square)

Create a square picture. This method uses the cutand gravity parameters from imagemagick

— c (=crop)

Crop the picture with w and h parameters. (c:800.100) for a 800px width and 100px height. By default the crop is centered.
You can specify a region with g:value option. Allowed values are: [NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast] (case sensitive)

— q (=qality)

Specify a quality between 0 to 100. Default options is used (80)

NOTE

  • h:100,w:100 is equivalent to s:100. The square mode is shorter.

  • h:100,w:800 is equivalent to c:800.100. The crop mode is shorter.

  • If you set a value bigger than the source picture is, the source value is kept. For example, if you have 800px width picture and you ask for a 999px picture width, the generated will be 800px width.

Errors

If scheme is not respected, a 500 error is produced, with a gently error message dispayed in the browser.

Examples

http://localhost:3000/w:400/file.jpg => force Width

http://localhost:3000/h:500/file.jpg => force Height

http://localhost:3000/s:600/file.jpg => square image

http://localhost:3000/c:600.100/file.jpg => panoramic picture

http://localhost:3000/c:600.100:g:South,q:10/file.jpg => panoramic picture cropped to South region and a vey low quality

Tips

If you want to know if the image delivered is cached or not, have a look to X-Hit-Cache header, (1 = cached, 0 = not cached)