0.4.0 • Published 6 years ago

imagecachejs v0.4.0

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

Express middleware for transforming images and caching them for quick retrieval

Get started

Install with npm or yarn:

npm install --save imagecachejs

You can then use imagecache in your project. The constructor imagecache() will return an express router which you can mount as a subpath for your express app

import express from 'express'
import imagecache from 'imagecachejs'

const app = express()

app.use(express.static('./public'))

app.use('/imagecache', imagecache({
  webRoot: 'public',
  sources: [
    'public',
    'http://localhost:8080'
  ]
}))

app.listen(8080, function () {
  console.log('Example app listening on port 8080')
})

Examples

You can view our example app with the following commands:

# checkout the repository
git clone https://github.com/mahaplatform/imagecachejs.git

# change directory
cd imagecachejs/examples

# install dependencies
npm install

# build the source
npm run build

# start the server
npm run start

Generating an Image

Once your server is up and running, you can invoke an image transformation using the following syntax:

# http://{hostname}/{mountPoint}/{transformationString}/{imagePath}
http://example.com/imagecache/bri=50&sat=30/images/kitten.png

By putting all of the image transformations in the url file path rather than a query string, the transformed file can easily be saved to filesystem and served as a static asset from static middleware (express.static), a web server (nginx, Apache), a content delivery network (Amazon CloudFront, Akamai), or a caching web proxy (Varnish, Squid).

Transformation Strings

Image transformations are invoked using a 'query string like' syntax. For example, if you want to brighten an image, decrease the contrast, and resize the image to a width of 250 pixels, the transformation string would be:

bri=15&con=-10&w=250

These transformations, however, will not necessarily be executed in the order given. If the sequence is important to you, use the op argument:

op[0][bri]=15&op[1][con]=-10&op[2][w]=250

Transformations

The following transformations are available through Imagecache:

  • Brightness (bri)
  • Contrast (con)
  • Hue (hue)
  • Saturation (sat)
  • Tint (tint)
  • Invert (invert)
  • Blur (blur)
  • Flip (flip)
  • Rotate (rot)
  • Padding (pad)
  • Border (border)
  • Crop (crop)
  • Resize (fit,w,h)

Brightness

Increase or decrease the brightness of an image

Contrast

Increase or decrease the contrast of an image

Hue

Rotate the hue of an image with a value between -360 and 360 degrees

Saturation

Increase or decrease the saturation of an image with an amount between -100% and 100%

Tint

Tint an image with a layer of any color with a opacity value between 1% and 100%

Invert

Invert the colors of the image

Blur

Blur image with a radius

Flip

Flip the image horizontally, vertically, or both

Rotate

Rotate image and then crop to largest possible rectangle with same aspect ratio

Padding

Put x pixels of padding around the image

Border

Draw an x pixel thick border around the image

Crop

Crop the image using a reactangle in the format "x,y,w,h"

Resize

Resize the image

Author & Credits

Imagecache was originally written by Greg Kops and is based upon his work with Think Topography and The Cornell Cooperative Extension of Tompkins County.

Special thanks to Oliver Moran and the Jimp project for building the engine that makes Imagecache possible!

0.4.0

6 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.18

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago