Skip to content

phillipoertel/resizing_image_server.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

In a web application, uploaded images are often needed in different sizes. This server resizes an image when first serving it, and caches it for faster serving on the next requests. This makes it very easy to add new image sizes later on, since nothing has to be pre-generated. The server uses node.js and ImageMagick.

Example

Request http://127.0.0.1:8000/200/sammy-davis-jr.jpg, and it sends this image in width 200, regardless if this size existed earlier. The only requirement is that the original size image exists.

It the resized image already exists, it will be served directly. If not, it is created, cached and served.

Installation

Install node.js first: http://nodejs.org/#download

> git clone git@github.com:phillipoertel/resizing_image_server.js.git resizing_image_server
> cd resizing_image_server
> rake setup
This will set up the following structure:

`— images
|— originals
`— resized
|— 100
|— 200

> node resizing_image_server.js

Now point your browser to: http://127.0.0.1:8000/200/sammy-davis-jr.jpg

Adding more sizes

To add a new size, create a new directory below “resized”.
This is the only way you control which image sizes are available.

Sizes currently can only be URL- and filesystem neutral strings, but with a bit of escaping all Image Magick geometry strings (http://is.gd/cjcci) should be supportable. The geometry is passed on to Image Magick directly from the URL.

Throughput

Stats for node version 0.1.96 on my local machine (OS X Intel Core 2 Duo 2.66GHz, 4GB RAM, SSD HD)

Disclaimer

This is a proof of concept, consider it alpha software.

About

A server to resize images at request time, written for node.js

Resources

Stars

Watchers

Forks

Packages

No packages published