bun install @karnak19/resize-it-sdk@1.1.1
curl "http://localhost:3000/images/resize/image.jpg?width=800&format=webp"
Open-source, high-performance image resizing and optimization service built with Bun and Elysia. Self-host your own image transformation API.
Built with Bun and Elysia for maximum performance. Resize and optimize images in milliseconds.
Uses Bun's lightweight, high-performance built-in S3 client for efficient storage operations.
Resize, crop, rotate, flip, and apply filters to your images with simple API parameters.
Keep your images and data on your own infrastructure. No third-party services accessing your content.
Process as many images as you need without worrying about monthly quotas or unexpected bills.
Modify the code to fit your specific needs. Add custom transformations or integrate with your existing systems.
/images/resize/:path
Resize and transform an image with various parameters
curl "http://localhost:3000/resize/image.jpg?width=800&format=webp"
curl "http://localhost:3000/resize/profile.png?width=200&height=200&grayscale=true"
curl "http://localhost:3000/resize/banner.jpg?width=1200&quality=85&rotate=90"
Resize-it comes with built-in Swagger documentation, making it easy to explore and test the API.
Access the interactive API documentation at /swagger endpoint.
Interactive API Documentation
Explore endpoints, test requests, and view response schemas
import { ResizeIt } from '@karnak19/resize-it-sdk';
// Initialize the client
const client = new ResizeIt({
baseUrl: 'http://localhost:3000'
});
// Generate a resized image URL
const imageUrl = client.getResizeUrl('image.jpg', {
width: 800,
height: 600,
format: 'webp',
quality: 90
});
Our official SDK makes it easy to integrate Resize-it into your applications. Available for JavaScript and TypeScript projects.
npm install @karnak19/resize-it-sdk@1.1.1
# or
bun install @karnak19/resize-it-sdk@1.1.1
The SDK provides a simple yet powerful interface for interacting
with the Resize-it service. The main class,
ResizeIt
, offers
methods for uploading images, generating resize URLs, and retrieving
resized images directly.
/**
* ResizeIt SDK for uploading and retrieving images
*/
export class ResizeIt {
private config: ResizeItConfig;
/**
* Create a new ResizeIt SDK instance
* @param config Configuration options
*/
constructor(config: ResizeItConfig) {
// ...
}
}
When initializing the SDK, you can provide the following configuration options:
Option | Type | Description | Default |
---|---|---|---|
baseUrl |
string | The base URL of your Resize-it service | Required |
timeout |
number | Request timeout in milliseconds | 30000 (30 seconds) |
apiKey |
string | API key for authentication (if enabled on the server) | undefined |
const client = new ResizeIt({
baseUrl: 'https://resize-it.example.com',
timeout: 60000, // 60 seconds
apiKey: 'your-api-key'
});
Upload an image to the Resize-it service. Supports Buffer, Blob, or base64 string inputs.
imageData
: Buffer | Blob | string - The image
data to upload
options
: UploadOptions - Upload configuration
options
Promise<UploadResponse> - A promise resolving to the upload response
// Upload an image from a file input
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];
const response = await client.uploadImage(file, {
filename: 'custom-name.jpg',
folder: 'uploads/2023'
});
console.log(response.path); // Path to the uploaded image
Generate a URL for a resized version of an image with the specified options.
imagePath
: string - Path to the image on the
server
options
: ResizeOptions - Resize configuration
options
string - The URL to the resized image
const imageUrl = client.getResizeUrl('uploads/profile.jpg', {
width: 400,
height: 400,
format: 'webp',
quality: 85,
grayscale: true
});
// Use in an img tag
const img = document.createElement('img');
img.src = imageUrl;
document.body.appendChild(img);
Fetch a resized image directly as a Blob, useful for further processing or displaying in the browser.
imagePath
: string - Path to the image on the
server
options
: ResizeOptions - Resize configuration
options
Promise<Blob> - A promise resolving to the image blob
// Get a resized image as a Blob
const imageBlob = await client.getResizedImage('banner.jpg', {
width: 1200,
format: 'avif',
quality: 90
});
// Create an object URL for the blob
const objectUrl = URL.createObjectURL(imageBlob);
// Use in an img element
document.querySelector('#banner').src = objectUrl;
The SDK supports all transformation options available in the Resize-it API.
Option | Type | Description |
---|---|---|
width |
number | Target width in pixels |
height |
number | Target height in pixels |
format |
string | Output format (webp, jpeg, png, avif) |
quality |
number | Output quality (1-100) |
fit |
string | Resize strategy (cover, contain, fill, inside, outside) |
position |
string | Position for cropping (top, right top, right, etc.) |
rotate |
number | Rotation angle in degrees |
flip |
boolean | Flip the image horizontally |
flop |
boolean | Flip the image vertically |
grayscale |
boolean | Convert to grayscale |
blur |
number | Apply Gaussian blur (sigma value) |
// Example: Upload an image and generate multiple sizes
async function processImage(file) {
const client = new ResizeIt({
baseUrl: 'https://resize-it.example.com'
});
try {
// 1. Upload the original image
const uploadResult = await client.uploadImage(file, {
folder: 'products'
});
// 2. Generate URLs for different sizes
const imagePath = uploadResult.path;
const thumbnailUrl = client.getResizeUrl(imagePath, {
width: 200,
height: 200,
fit: 'cover',
format: 'webp'
});
const previewUrl = client.getResizeUrl(imagePath, {
width: 800,
format: 'webp'
});
const fullsizeUrl = client.getResizeUrl(imagePath, {
width: 1920,
format: 'webp',
quality: 90
});
return {
original: imagePath,
thumbnail: thumbnailUrl,
preview: previewUrl,
fullsize: fullsizeUrl
};
} catch (error) {
console.error('Failed to process image:', error);
throw error;
}
}
Before installing Resize-it, make sure you have the following:
git clone https://github.com/karnak19/resize-it.git
cd resize-it
bun install
# Or if you prefer npm
npm install
cp .env.example .env
nano .env # Edit with your configuration
See the Configuration Options table for available settings.
bun run dev # Development mode with hot reload
# or
bun run start # Production mode
The server will start at http://localhost:3000 by default.
For containerized deployment, you can use our official Docker image:
docker pull karnak19/resize-it:latest
docker run -p 3000:3000 \
-v ./images:/app/images \
-v ./config:/app/config \
-e S3_ENDPOINT=your-s3-endpoint \
-e S3_ACCESS_KEY=your-access-key \
-e S3_SECRET_KEY=your-secret-key \
karnak19/resize-it:latest
For a complete setup with MinIO and Dragonfly:
wget https://raw.githubusercontent.com/karnak19/resize-it/main/docker-compose.yml
docker-compose up -d
Variable | Description | Default |
---|---|---|
Server Configuration | ||
HOST | Server host | 0.0.0.0 |
PORT | Server port | 3000 |
Storage Configuration | ||
S3_ENDPOINT | S3 endpoint URL | localhost |
S3_PORT | S3 port | 9000 |
S3_USE_SSL | Use SSL for S3 connection | false |
S3_REGION | S3 region | us-east-1 |
S3_BUCKET | S3 bucket name | images |
S3_ACCESS_KEY | S3 access key | minioadmin |
S3_SECRET_KEY | S3 secret key | minioadmin |
Image Processing Configuration | ||
MAX_WIDTH | Maximum allowed image width | 1920 |
MAX_HEIGHT | Maximum allowed image height | 1080 |
IMAGE_QUALITY | Default image quality (1-100) | 80 |
Cache Configuration | ||
CACHE_ENABLED | Enable image caching | true |
CACHE_MAX_AGE | Cache time-to-live (seconds) | 86400 |
Dragonfly Configuration | ||
DRAGONFLY_ENABLED | Enable Dragonfly caching | false |
DRAGONFLY_HOST | Dragonfly host | localhost |
DRAGONFLY_PORT | Dragonfly port | 6379 |
DRAGONFLY_CACHE_TTL | Dragonfly cache TTL (seconds) | 86400 |
Security Configuration | ||
ENABLE_API_KEY_AUTH | Enable API key authentication | false |
API_KEYS | Comma-separated list of valid API keys | dev-api-key |
RATE_LIMIT_ENABLED | Enable rate limiting | true |
RATE_LIMIT_WINDOW_MS | Rate limit window in milliseconds | 60000 |
RATE_LIMIT_MAX | Maximum requests per window | 100 |
CORS_ALLOWED_ORIGINS | Comma-separated list of allowed origins | * |
Debug Configuration | ||
DEBUG | Enable debug mode | false |
Join the community of developers who trust Resize-it v1.1.1 for their image processing needs.