# @jambff/supabase-image-resizer

> An image resize service backed by Supabase.

Latest version **1.2.0** (published 2023-01-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jambff/supabase-image-resizer
pnpm add @jambff/supabase-image-resizer
yarn add @jambff/supabase-image-resizer
bun add @jambff/supabase-image-resizer
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2023-01-20 |
| First published | 2023-01-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 18 |
| Unpacked size | 51.7 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alex Mendes |
| Maintainers | alexmendes |

## Links

- npm: https://www.npmjs.com/package/@jambff/supabase-image-resizer
- Repository: https://github.com/jambff/supabase-image-resizer
- Homepage: https://github.com/jambff/supabase-image-resizer#readme
- Issues: https://github.com/jambff/supabase-image-resizer/issues
- npm.io page: https://npm.io/package/@jambff/supabase-image-resizer

## Dependencies (18)

- [qs](https://npm.io/package/qs.md) ^6.11.0
- [cors](https://npm.io/package/cors.md) ^2.8.5
- [lusca](https://npm.io/package/lusca.md) ^1.7.0
- [sharp](https://npm.io/package/sharp.md) ^0.31.3
- [dotenv](https://npm.io/package/dotenv.md) ^16.0.1
- [consola](https://npm.io/package/consola.md) ^2.15.3
- [express](https://npm.io/package/express.md) ^4.18.1
- [get-port](https://npm.io/package/get-port.md) ^5.1.1
- [@types/qs](https://npm.io/package/@types/qs.md) ^6.9.7
- [file-type](https://npm.io/package/file-type.md) ^16.5.3
- [timestring](https://npm.io/package/timestring.md) ^6.0.0
- [current-url](https://npm.io/package/current-url.md) ^2.1.2
- [app-root-path](https://npm.io/package/app-root-path.md) ^3.0.0
- [connect-timeout](https://npm.io/package/connect-timeout.md) ^1.9.0
- [smartcrop-sharp](https://npm.io/package/smartcrop-sharp.md) ^2.0.7
- [imagemin-pngquant](https://npm.io/package/imagemin-pngquant.md) ^9.0.2
- [@supabase/supabase-js](https://npm.io/package/@supabase/supabase-js.md) ^2.4.0
- [animated-gif-detector](https://npm.io/package/animated-gif-detector.md) ^1.2.0

## Recent versions

- 1.2.0 (latest) — 2023-01-20
- 1.1.2 — 2023-01-20
- 1.1.1 — 2023-01-20
- 1.1.0 — 2023-01-20
- 1.0.3 — 2023-01-19
- 1.0.2 — 2023-01-19
- 1.0.1 — 2023-01-19
- 1.0.0 — 2023-01-19

## README

# Jambff Supabase Image Resizer

An image resize service backed by Supabase.

## Deploying with DigitalOcean

### Deploy using App Platform

[![Deploy to DO](https://www.deploytodo.com/do-btn-blue.svg)](https://cloud.digitalocean.com/apps/new?repo=https://github.com/jambff/supabase-image-resizer/tree/main)

### Deploy using Functions

Install and configure [doctl](https://docs.digitalocean.com/reference/doctl/how-to/install/),
along with the serverless plugin:

```text
doctl serverless install
```

Create a namespace for the function:

```text
doctl serverless namespaces create --label image-resizer --region lon1
```

Create a .env file and populate with your `SUPABASE_PROJECT_URL` and `SUPABASE_SERVICE_ROLE_KEY`.

```text
cp .env.template .env
```

Deploy the function:

```text
doctl serverless deploy . --env .env
```

## Manual setup

Install the package:

```text
yarn install @jambff/supabase-image-resizer
```

Via a `.env` file, or some other mechanism depending on your environment, set
the `SUPABASE_PROJECT_URL` and `SUPABASE_SERVICE_ROLE_KEY` as environment
variables, which can be retrieved from the Supabase dashboard.

Launch the server with:

```js
import { launchServer } from '@jambff/supabase-image-resizer';

launchServer();
```

## Usage

Image requests are made in the following format:

```text
http://your.domain.com/<BUCKET>/<FOLDER>/<FILE_NAME>
```

for example:

```text
http://your.domain.com/images/public/my-image.jpg
```

The following query parameters are available:

| URL Arg | Type | Description |
|---|----|---|
|`w`|Number|Max width of the image.|
|`h`|Number|Max height of the image.|
|`quality`|Number, 0-100|Image quality.|
|`resize`|String, "w,h"|A comma separated string of the target width and height in pixels. Crops the image.|
|`crop_strategy`|String, "smart", "entropy", "attention"|There are 3 automatic cropping strategies for use with `resize`: <ul><li>`attention`: good results, ~70% slower</li><li>`entropy`: mediocre results, ~30% slower</li><li>`smart`: best results, ~50% slower</li>|
|`gravity`|String|Alternative to `crop_strategy`. Crops are made from the center of the image by default, passing one of "north", "northeast", "east", "southeast", "south", "southwest", "west", "northwest" or "center" will crop from that edge.|
|`fit`|String, "w,h"|A comma separated string of the target maximum width and height. Does not crop the image.|
|`crop`|Boolean\|String, "x,y,w,h"|Crop an image by percentages x-offset, y-offset, width and height (x,y,w,h). Percentages are used so that you don’t need to recalculate the cropping when transforming the image in other ways such as resizing it. You can crop by pixel values too by appending `px` to the values. `crop=160px,160px,788px,788px` takes a 788 by 788 pixel square starting at 160 by 160.|
|`zoom`|Number|Zooms the image by the specified amount for high DPI displays. `zoom=2` produces an image twice the size specified in `w`, `h`, `fit` or `resize`. The quality is automatically reduced to keep file sizes roughly equivalent to the non-zoomed image unless the `quality` argument is passed.|
|`webp`|Boolean, 1|Force WebP format.|
|`lb`|String, "w,h"|Add letterboxing effect to images, by scaling them to width, height while maintaining the aspect ratio and filling the rest with black or `background`.|
|`background`|String|Add background color via name (red) or hex value (%23ff0000). Don't forget to escape # as `%23`.|

---
_Source: https://npm.io/package/@jambff/supabase-image-resizer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
