GitPedia

Ipx

🖼️ High performance, secure and easy-to-use image optimizer.

From unjs·Updated June 11, 2026·View on GitHub·

High performance, secure and easy-to-use image optimizer powered by [sharp](https://github.com/lovell/sharp) and [svgo](https://github.com/svg/svgo). The project is written primarily in TypeScript, distributed under the MIT License license, first published in 2017. It has gained significant community traction with 2,422 stars and 88 forks on GitHub. Key topics include: cdn, docker, image, libvips, optimize.

Latest release: v4.0.0-alpha.1
December 4, 2025View Changelog →

🖼️ IPX

<!-- automd:badges color=yellow -->

npm version
npm downloads

<!-- /automd -->

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

Used by Nuxt Image and Netlify and open to everyone!

Migration from v3 to v4

[!NOTE]
This is the active development branch for IPX v4. Check out v3 for v3 docs.

  • The server creation APIs have changed. See the Programmatic API section for examples.
  • The JSON error format has changed from { error: string } to { status, statusText, message }.

Using CLI

You can use ipx command to start server.

Using npx:

bash
npx ipx serve --dir ./

Using bun

bash
bunx ipx serve --dir ./

The default serve directory is the current working directory.

Programmatic API

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

Example: Using built-in server

<!-- automd:file code src="./examples/serve.ts" -->
ts
import { serveIPX, createIPX, ipxFSStorage, ipxHttpStorage } from "ipx"; const ipx = createIPX({ storage: ipxFSStorage({ dir: "./public" }), httpStorage: ipxHttpStorage({ domains: ["picsum.photos"] }), alias: { "/picsum": "https://picsum.photos" }, }); // http://localhost:3000/w_512/picsum/1000 serveIPX(ipx);
<!-- /automd -->

Example: Using with h3

<!-- automd:file code src="./examples/h3.ts" -->
ts
import { H3, serve } from "h3"; import { createIPX, ipxFSStorage, ipxHttpStorage, createIPXFetchHandler, } from "ipx"; const ipx = createIPX({ storage: ipxFSStorage({ dir: "./public" }), httpStorage: ipxHttpStorage({ domains: ["picsum.photos"] }), alias: { "/picsum": "https://picsum.photos" }, }); const app = new H3(); app.mount("/ipx", createIPXFetchHandler(ipx)); // http://localhost:3000/ipx/w_512/picsum/1000 serve(app);
<!-- /automd -->

Example: Using with express

<!-- automd:file code src="./examples/express.ts" -->
ts
import Express from "express"; import { createIPX, ipxFSStorage, ipxHttpStorage, createIPXNodeHandler, } from "ipx"; const ipx = createIPX({ storage: ipxFSStorage({ dir: "./public" }), httpStorage: ipxHttpStorage({ domains: ["picsum.photos"] }), alias: { "/picsum": "https://picsum.photos" }, }); const app = Express(); app.use("/ipx", createIPXNodeHandler(ipx)); // http://localhost:3000/ipx/w_512/picsum/1000 app.listen(3000, () => { console.log("Server is running on http://localhost:3000"); });
<!-- /automd -->

URL Examples

Get original image:

/_/static/buffalo.png

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

/f_webp/static/buffalo.png

Automatically convert to a preferred format (avif/webp/jpeg). Uses the browsers accept header to negotiate:

/f_auto/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 or /w_200/buffalo.png
height / hDocs/height_200/buffalo.png or /h_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.
cropDocs/crop_{left}_{top}_{width}_{height}/buffalo.pngAlias for extract. Extract/crop a region of the image.
format / fDocs/format_webp/buffalo.png or /f_webp/buffalo.pngSupported format: jpg, jpeg, png, webp, avif, gif, heif, tiff and auto (experimental only with middleware)
quality / q_/quality_50/buffalo.png or /q_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
flattenDocs/flatten/buffalo.pngRemove alpha channel, if any, and replace with background colour.
modulateDocs/modulate_brightness_saturation_hue/buffalo.pngTransforms the image using brightness, saturation and hue rotation.
cropDocs/crop_{left}_{top}_{width}_{height}/buffalo.pngAlias for extract. Extract/crop a region of the image.
animated / a-/animated/buffalo.gif or /a/buffalo.gifExperimental

License

MIT

Contributors

Showing top 12 contributors by commit count.

View all contributors on GitHub →

This article is auto-generated from unjs/ipx via the GitHub API.Last fetched: 6/14/2026