3.0.1 • Published 3 months ago

ipx v3.0.1

Weekly downloads
1,596
License
MIT
Repository
github
Last release
3 months ago

🖼️ IPX

npm version npm downloads

!NOTE This is the active branch for IPX v2. Check out ipx/v1 for v1 docs.

High performance, secure and easy-to-use image optimizer powered by sharp and svgo.

Used by Nuxt Image and Netlify and open to everyone!

Using CLI

You can use ipx command to start server.

Using npx:

npx ipx serve --dir ./

Usin bun

bun x npx ipx serve --dir ./

The default serve directory is the current working directory.

Programatic API

You can use IPX as a middleware or directly use IPX interface.

import { createIPX, ipxFSStorage, ipxHttpStorage } from "ipx";

const ipx = createIPX({
  storage: ipxFSStorage({ dir: "./public" }),
  httpStorage: ipxHttpStorage({ domains: ["picsum.photos"] }),
});

Example: Using with unjs/h3:

import { listen } from "listhen";
import { createApp, toNodeListener } from "h3";
import {
  createIPX,
  ipxFSStorage,
  ipxHttpStorage,
  createIPXH3Handler,
} from "ipx";

const ipx = createIPX({
  storage: ipxFSStorage({ dir: "./public" }),
  httpStorage: ipxHttpStorage({ domains: ["picsum.photos"] }),
});

const app = createApp().use("/", createIPXH3Handler(ipx));

listen(toNodeListener(app));

Example: Using express:

import { listen } from "listhen";
import express from "express";
import {
  createIPX,
  ipxFSStorage,
  ipxHttpStorage,
  createIPXNodeServer,
} from "ipx";

const ipx = createIPX({
  storage: ipxFSStorage({ dir: "./public" }),
  httpStorage: ipxHttpStorage({ domains: ["picsum.photos"] }),
});

const app = express().use("/", createIPXNodeServer(ipx));

listen(app);

URL Examples

Get original image:

/_/static/buffalo.png

Change format to webp and keep other things same as source:

/f_webp/static/buffalo.png

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

/w_200/static/buffalo.png

Resize to 200x200px using embed method and change format to webp:

/embed,f_webp,s_200x200/static/buffalo.png

Config

You can universally customize IPX configuration using IPX_* environment variables.

  • IPX_ALIAS

    • Default: {}

Filesystem Source Options

(enabled by default with CLI only)

IPX_FS_DIR

  • Default: . (current working directory)

IPX_FS_MAX_AGE

  • Default: 300

HTTP(s) Source Options

(enabled by default with CLI only)

IPX_HTTP_DOMAINS

  • Default: []

IPX_HTTP_MAX_AGE

  • Default: 300

IPX_HTTP_FETCH_OPTIONS

  • Default: {}

IPX_HTTP_ALLOW_ALL_DOMAINS

  • Default: false

Modifiers

PropertyDocsExampleComments
width / wDocs/width_200/buffalo.png
height / hDocs/height_200/buffalo.png
resize / sDocs/s_200x200/buffalo.png
kernelDocs/s_200x200,kernel_nearest/buffalo.pngSupported kernel: nearest, cubic, mitchell, lanczos2 and lanczos3 (default).
fitDocs/s_200x200,fit_outside/buffalo.pngSets fit option for resize.
position / posDocs/s_200x200,pos_top/buffalo.pngSets position option for resize.
trimDocs/trim_100/buffalo.png
extendDocs/extend_{top}_{right}_{bottom}_{left}/buffalo.pngExtend / pad / extrude one or more edges of the image with either the provided background colour or pixels derived from the image.
background / b_/r_45,b_00ff00/buffalo.png
extractDocs/extract_{left}_{top}_{width}_{height}/buffalo.pngExtract/crop a region of the image.
format / fDocs/format_webp/buffalo.pngSupported format: jpg, jpeg, png, webp, avif, gif, heif, tiff and auto (experimental only with middleware)
quality / q_/quality_50/buffalo.pngAccepted values: 0 to 100
rotateDocs/rotate_45/buffalo.png
enlarge_/enlarge,s_2000x2000/buffalo.pngAllow the image to be upscaled. By default the returned image will never be larger than the source in any dimension, while preserving the requested aspect ratio.
flipDocs/flip/buffalo.png
flopDocs/flop/buffalo.png
sharpenDocs/sharpen_30/buffalo.png
medianDocs/median_10/buffalo.png
blurDocs/blur_5/buffalo.png
gammaDocs/gamma_3/buffalo.png
negateDocs/negate/buffalo.png
normalizeDocs/normalize/buffalo.png
thresholdDocs/threshold_10/buffalo.png
tintDocs/tint_1098123/buffalo.png
grayscaleDocs/grayscale/buffalo.png
animated-/animated/buffalo.gifExperimental

License

MIT

3.0.1

3 months ago

3.0.1-0

3 months ago

3.0.0

4 months ago

2.1.0

4 months ago

2.0.2

6 months ago

2.0.1

6 months ago

2.0.0-1

7 months ago

2.0.0-0

8 months ago

2.0.0

7 months ago

1.3.1

7 months ago

1.3.0

8 months ago

1.2.0

11 months ago

1.0.1

1 year ago

1.1.0

12 months ago

1.0.0

1 year ago

1.0.0-1

1 year ago

1.0.0-0

1 year ago

1.0.0-2

1 year ago

0.9.11

2 years ago

0.9.10

2 years ago

0.9.8

2 years ago

0.9.7

2 years ago

0.9.9

2 years ago

0.9.6

2 years ago

0.9.4

2 years ago

0.9.3

2 years ago

0.8.1

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.9.0

3 years ago

0.8.0

3 years ago

0.7.2

3 years ago

0.6.7

3 years ago

0.6.6

3 years ago

0.6.3

3 years ago

0.7.1

3 years ago

0.6.5

3 years ago

0.6.4

3 years ago

0.7.0

3 years ago

0.6.2

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.5.8

3 years ago

0.5.7

3 years ago

0.5.6

3 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.5

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.8

3 years ago

0.4.7

3 years ago

0.4.6

3 years ago

0.4.5

3 years ago

0.4.4

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.4.0-rc.3

4 years ago

0.4.0-rc.2

4 years ago

0.4.0-rc.1

4 years ago

0.3.2

4 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.1

6 years ago