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

resize-as-a-service

v1.0.1

Published

An image resizing API, useful for blogs and such

Downloads

26

Readme

Resize-as-a-Service

When you've got a blog or a web application there are oft times that you want to store a local copy of some remote image you're linking to (so that it doesn't disappear and leave you content-less) and there are also times that you want to resize such an image so that it downloads faster.

This does both.

Tada!

  • /resize/api?width={{width}}&url={{url}}
  • /resize/api?height={{height}}&url={{url}}
  • /resize/api?height={{height}}&width={{width}}&url={{url}}
  • /resize/api?format={{png|jpg|gif}}&quality=85&url={{url}}

NOTE: the local cache of the image will include a direct download of the original image as well as the modified image.

NOTE: resize will only make images smaller, not larger.

For best results you may wish to call encodeURIComponent(picUrl) so that the server isn't confused by excess ? and &.

Example

See https://github.com/coolaj86/resize-as-a-service-example for a 60-second tutorial.

All Parameters

  • &height=100 - bound the height to 100px and adjust the width proportionally
  • &width=150 - bound the width to 150px and adjust the height proportionally
  • &url=encodeURIComponent('http://example.com/image.png') - the image to cache / resize
    • NOTE: all URLs SHOULD be URI encoded, but URLs with ? and & MUST be encoded.
  • &format=jpg|png|gif - convert to this format
  • &quality=85 - quality (jpg/gif) or compression (png) level
  • &refresh=86400 - the image will be checked for updates when it is accessed at least one day (86400 seconds) later
    • NOTE: if there is an error retrieving the new image, the cached copy will be used
  • &state=123 - never expire the cache for this image and save it as state 123

state

Once an image is cached the source image will not be checked for updates (unless refresh is specified).

If you know that image has changed since it was cached and you want to use the newer image, specify a state parameter. If that state doesn't exist the image will be redownloaded and the result will be cached as that state.

Install & Usage

# Ubuntu
sudo apt-get install graphicsmagick imagemagick

# OS X
brew install graphicsmagick imagemagick

Example with Connect / Express

'use strict';

var http = require('http')
  , serve = require('../server')
  , port
  , server
  , connect = require('connect') // or express
  , path = require('path')
  , resizer = require('resize-as-a-service')
  , app = connect()
  , conf
  ;

port = port || process.argv[2] || 3000;

conf = {
  imagesFolder: path.resolve(__dirname, 'images', 'resized')
, originalsFolder: path.resolve(__dirname, 'images', 'originals')
, apiRoute: '/api'
};

app
  .use('/resize', resizer.create(conf))
  .use(function (req, res) {
    res.end('You probably thought this was a path to a real image... Nope. Chuck Testa!');
  })
  ;

server = http.createServer(serve.create());
server.listen(port, function() {
  console.log('Listening on port ' + port);
});

Configuration

{ apiRoute: '/api'
, mountedAt: null // i.e. /resize
, imageRoute: '/assets'
, imageFolder: path.join(__dirname, '/images')
}

How it works

  • Turns url into an md5 hash.
  • Checks originalsFolder for the file metadata by that hash and hash + extension
    • If the file doesn't exist, it downloads it and extracts metadata
  • Then it turns the query parameters into a hash and checks for the metadata file
    • If the file doesn't exist, it resizes the image
    • Otherwise it passes the path to the static file server

Some of the internals may change in the future.

Copyright and license

Code and documentation copyright 2014 AJ ONeal Tech, LLC.

Code released under the Apache license.

Docs released under Creative Commons.