ipx
<div align="center"> <img src="./logo.png" alt="IPX Logo" /> </div>
Last updated a month ago by pi0 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ipx 
SYNC missed versions from official npm registry.
IPX Logo

Docker Pulls NPM Vernion NPM Downloads Package Size

High performance, secure and easy to use image proxy based on sharp and libvips.

  • Easy deployment
  • Configurable operations
  • Built-in secure cache with human readable entries and resistant against duplicates
  • Adapter based cache and input
  • Auto cache cleaner
  • Twelve factor friendly
  • Client SDK for URL generation

Usage

Using NPM package

You can use ipx command to start server using:

$ npx ipx

Docker Image

Latest docker image is automatically built under pooya/ipx.

Run a test server:

docker run \
  -it \
  --rm \
  --volume ./storage:/app/storage:ro \
  --volume ./cache:/app/cache \
  --port 3000:3000
  pooya/ipx

Using docker-compose:

version: '3'
services:
  ipx:
    image: pooya/ipx
    volumes:
      - ./storage:/app/storage:ro
      - ./cache:/app/cache
    ports:
      - 3000:3000

Programatic Usage

You can use IPX as a Connect/Express middleware or directly use IPX class.

import { IPX, IPXMiddleware } from 'ipx'

const ipx = new IPX(/* options */)

const app = express()
app.use('/image', IPXMiddleware(ipx))

API

/{format}/{operations}/{src}

Operations are separated by a colon , (Example: op1,op2) and their arguments separated using underscore _ (Example: s_200_300)

ََ‍‍Use _ value in place for {format} or {operations} to keep original values of source image.

Possible values for format: jpeg,webp or png.

Examples

Just change format to webp and keep other things same as source:

http://cdn.example.com/webp/_/avatars/buffalo.png

Keep original format (png) and set width to 200:

http://cdn.example.com/_/w_200/avatars/buffalo.png

Resize to 200x300px using embed method and change format to jpg:

http://cdn.example.com/jpg/s_200_300,embed/avatars/buffalo.png

Operations

Operation Arguments Example Description
s width, height s_200_300 Resize image.
w width w_200 Change image with.
h height h_200 Change image height.
embed - embed Preserving aspect ratio, resize the image to the maximum width or height specified then embed on a background of the exact width and height specified.
max - max Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to the width and height specified.
min - min Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to the width and height specified.

Config

Config can be customized using IPX_* environment variables.

  • IPX_PORT (or PORT) Default: 3000

  • IPX_INPUT_ADAPTER

    • Default: fs
  • IPX_INPUT_DIR

    • Default: storage
  • IPX_CACHE_ADAPTER

    • Default: fs
  • IPX_CACHE_DIR

    • Default: cache
  • IPX_CACHE_CLEAN_CRON

    • Default: 0 0 3 * * * (every night at 3:00 AM)
  • IPX_CACHE_CLEAN_MINUTES

    • Default: 24 * 60 (24 hours)

Client

Import client:

import { img } from 'ipx/client'

const { img } = require('ipx/client')

img() is a factory function to configure base options:

// getImage: (path, opts?, format?) => URL
const getImage = img({
  baseURL = 'https://cdn.example.com',
  basePath = 'uploads',
  opts = [], // Default opts
  format = 'jpg',
  presets: {
    chrome400: {
      format: 'webp',
      opts: { s: ['400', '400']}
    }
  }
})

getImage('posts/ipx.png', { w: 200 }) // => https://cdn.example.com/jpg/w_200/uploads/posts/ipx.png

getImage.chrome400('posts/ipx.png') // => https://cdn.example.com/webp/s_400_400/uploads/posts/ipx.png

License

MIT - Pooya Parsa

Current Tags

  • 0.4.0-rc.3                                ...           beta (3 months ago)
  • 0.4.8                                ...           latest (a month ago)

19 Versions

  • 0.4.8                                ...           a month ago
  • 0.4.7                                ...           a month ago
  • 0.4.6                                ...           2 months ago
  • 0.4.5                                ...           2 months ago
  • 0.4.4                                ...           2 months ago
  • 0.4.3                                ...           2 months ago
  • 0.4.2                                ...           2 months ago
  • 0.4.1                                ...           2 months ago
  • 0.4.0                                ...           2 months ago
  • 0.4.0-rc.3                                ...           3 months ago
  • 0.4.0-rc.2                                ...           3 months ago
  • 0.4.0-rc.1                                ...           3 months ago
  • 0.3.2                                ...           4 months ago
  • 0.3.1                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 8
Last Day 0
Last Week 4
Last Month 38
Dependencies (11)

Copyright 2014 - 2017 © taobao.org |