No description
- TypeScript 80.4%
- Dockerfile 10.6%
- Makefile 9%
|
|
||
|---|---|---|
| .gitea/workflows | ||
| .dockerignore | ||
| .editorConfig | ||
| .gitignore | ||
| bun.lockb | ||
| docker-compose.yml | ||
| Dockerfile | ||
| index.test.ts | ||
| index.ts | ||
| Makefile | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
resize-img-api
Image resizing and format conversion API built with Hono and Sharp.
API Endpoints
Resize API
/api/imgresize/:width/:height/:url
Resize images to specified dimensions.
:widthand:heightcan be numbers in pixels orauto:urlshould be URL encoded (useencodeURIComponent()in JS)
Query parameters:
?format=- Output format:avif,gif,heif,jpeg,jpg,jp2,pdf,png,svg,tiff,webp(default:jpeg)?fit=- Resize fit mode:cover,contain,fill,inside,outside(default:inside)
Example:
/api/imgresize/200/200/https%3A%2F%2Fmemori.ai%2Flogo.png?format=png
Convert API
/api/convert/:format/:url
Convert images between different formats (e.g., HEIC to PNG/JPEG).
:format- Target format:avif,gif,heif,jpeg,jpg,jp2,pdf,png,svg,tiff,webp:urlshould be URL encoded
Example:
/api/convert/png/https%3A%2F%2Fexample.com%2Fimage.heic
Docker
Build and run using Make:
make build # Build Docker image
make run # Start container
make test # Run tests (requires container running)
make run-test # Build, run container, and run tests
make stop # Stop container
make clean # Stop container and remove image
Or manually:
docker build -t resize-img-api .
docker run -p 8787:8787 resize-img-api
Development
Install dependencies:
bun install
Run locally:
bun start # Production mode
bun dev # Development mode with hot reloading
Run tests:
bun test # Run tests (requires server running on localhost:8787)
make run-test # Start container and run tests
Notes
- The API supports HEIC/HEIF format conversion (requires libvips built with HEIC support)
- Images are cached with
Cache-Control: s-maxage=31536000, stale-while-revalidate - URL encoding is required for image URLs (use
encodeURIComponent()in JavaScript)
This project was created using bun init in bun v1.0.26. Bun is a fast all-in-one JavaScript runtime.