resize-img-api/README.md

71 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

2024-03-25 10:17:19 +01:00
# resize-img-api
The structure of the API path is:
```
/api/imgresize/:width/:height/:url
```
Where `:width` and `:height` can be numbers in pixels or `auto`.
The `:url` is the URL of the image to be resized and should be URL encoded, which can be done in JS with `encodeURIComponent`(). See [MDN ref](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent).
Example encoded URL for [https://memori.ai/logo.png](https://memori.ai/logo.png):
```
https%3A%2F%2Fmemori.ai%2Flogo.png
```
Then call the API as, for example:
```
/api/imgresize/200/200/https%3A%2F%2Fmemori.ai%2Flogo.png
```
2024-03-25 10:31:12 +01:00
You can also specify a format using the querystring `?format=` and indicating one of the following: `avif`, `gif`, `heif`, `jpeg`, `jpg`, `pdf`, `png`, `svg`, `tiff`, `webp`. (Note: Experimental!)
2024-03-25 10:17:19 +01:00
Another querystring parameter is `fit` which can be `cover`, `contain`, `fill`, `inside`, `outside` (Ref: [sharp](https://sharp.pixelplumbing.com/api-resize#resize)). Default is `inside`.
2024-03-25 10:17:19 +01:00
## Docker
To build the Docker image:
```bash
docker build -t resize-img-api .
```
To run the Docker container:
```bash
docker run -p 8787:8787 resize-img-api
```
Using the published image:
```bash
2024-05-21 21:21:21 +02:00
docker run -p 8787:8787 code.nzambello.dev/nzambello/resize-img-api:latest
2024-03-25 10:17:19 +01:00
```
## Development
To install dependencies:
```bash
bun install
```
To run:
```bash
bun start
```
Or in development mode with hot reloading:
```bash
bun dev
```
This project was created using `bun init` in bun v1.0.26. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.