|
| 1 | +# @srcset/imgproxy |
| 2 | + |
| 3 | +[![ESM-only package][package]][package-url] |
| 4 | +[![NPM version][npm]][npm-url] |
| 5 | +[![Node version][node]][node-url] |
| 6 | +[![Dependencies status][deps]][deps-url] |
| 7 | +[![Install size][size]][size-url] |
| 8 | +[![Build status][build]][build-url] |
| 9 | +[![Coverage status][coverage]][coverage-url] |
| 10 | + |
| 11 | +[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg |
| 12 | +[package-url]: https://nodejs.org/api/esm.html |
| 13 | + |
| 14 | +[npm]: https://img.shields.io/npm/v/%40srcset%2Fimgproxy.svg |
| 15 | +[npm-url]: https://npmjs.com/package/@srcset/imgproxy |
| 16 | + |
| 17 | +[node]: https://img.shields.io/node/v/%40srcset%2Fimgproxy.svg |
| 18 | +[node-url]: https://nodejs.org |
| 19 | + |
| 20 | +[deps]: https://img.shields.io/librariesio/release/npm/%40srcset%2Fimgproxy |
| 21 | +[deps-url]: https://libraries.io/npm/%40srcset%2Fimgproxy |
| 22 | + |
| 23 | +[size]: https://deno.bundlejs.com/badge?q=%40srcset%2Fimgproxy |
| 24 | +[size-url]: https://bundlejs.com/?q=%40srcset%2Fimgproxy |
| 25 | + |
| 26 | +[build]: https://img.shields.io/github/actions/workflow/status/TrigenSoftware/srcset/tests.yml?branch=main |
| 27 | +[build-url]: https://github.com/TrigenSoftware/srcset/actions |
| 28 | + |
| 29 | +[coverage]: https://img.shields.io/codecov/c/github/TrigenSoftware/srcset.svg |
| 30 | +[coverage-url]: https://app.codecov.io/gh/TrigenSoftware/srcset |
| 31 | + |
| 32 | +Adapter for [imgproxy](https://imgproxy.net/): srcset variant urls for content images, e.g. from an API or a CMS. |
| 33 | + |
| 34 | +- 🌐 Runtime builder of loader-shaped srcset objects, isomorphic: browser and server |
| 35 | +- 🔒 Presets support via the `processing` hook - no transformations exposed to the browser |
| 36 | +- ✍️ Url signing on the server side |
| 37 | +- 🛠 Passthrough mode for local development without a running imgproxy instance |
| 38 | + |
| 39 | +## Install |
| 40 | + |
| 41 | +```bash |
| 42 | +# pnpm |
| 43 | +pnpm add @srcset/imgproxy @srcset/runtime |
| 44 | +# yarn |
| 45 | +yarn add @srcset/imgproxy @srcset/runtime |
| 46 | +# npm |
| 47 | +npm i @srcset/imgproxy @srcset/runtime |
| 48 | +``` |
| 49 | + |
| 50 | +## Usage |
| 51 | + |
| 52 | +Srcset objects for CMS images: |
| 53 | + |
| 54 | +```ts |
| 55 | +import { Imgproxy } from '@srcset/imgproxy' |
| 56 | + |
| 57 | +const imgproxy = new Imgproxy({ endpoint: 'https://imgproxy.example.com' }) |
| 58 | +const { src, srcSet, srcMap } = imgproxy.image(photo.url, { |
| 59 | + width: [600, 1200], |
| 60 | + format: ['webp', 'jpg'] |
| 61 | +}) |
| 62 | +``` |
| 63 | + |
| 64 | +Signed urls, on the server side: |
| 65 | + |
| 66 | +```ts |
| 67 | +import { sign } from '@srcset/imgproxy/sign' |
| 68 | + |
| 69 | +const imgproxy = new Imgproxy({ |
| 70 | + endpoint: 'https://imgproxy.example.com', |
| 71 | + signer: sign({ key, salt }) |
| 72 | +}) |
| 73 | +``` |
| 74 | + |
| 75 | +Passthrough mode - untouched source urls, e.g. for local development without a running imgproxy instance: |
| 76 | + |
| 77 | +```ts |
| 78 | +const imgproxy = new Imgproxy({ |
| 79 | + endpoint: 'https://imgproxy.example.com', |
| 80 | + passthrough: import.meta.env.DEV |
| 81 | +}) |
| 82 | +``` |
| 83 | + |
| 84 | +## Documentation |
| 85 | + |
| 86 | +For more details, guides and API references, check out the [documentation website](https://srcset.js.org/proxies/imgproxy/). |
0 commit comments