bun install @karnak19/resize-it-sdk@1.1.1
curl "http://localhost:3000/images/resize/image.jpg?width=800&format=webp"

Resize-it v1.1.1

Open-source, high-performance image resizing and optimization service built with Bun and Elysia. Self-host your own image transformation API.

Processing Speed
10x
Faster than traditional solutions
Open Source
100%
Free and open source
File Size Reduction
70%
Average optimization

Why Choose Resize-it?

Lightning Fast

Built with Bun and Elysia for maximum performance. Resize and optimize images in milliseconds.

S3 Integration

Uses Bun's lightweight, high-performance built-in S3 client for efficient storage operations.

Flexible Transformations

Resize, crop, rotate, flip, and apply filters to your images with simple API parameters.

Benefits of Self-Hosting

  • Complete Privacy & Control

    Keep your images and data on your own infrastructure. No third-party services accessing your content.

  • No Usage Limits or Costs

    Process as many images as you need without worrying about monthly quotas or unexpected bills.

  • Customizable & Extensible

    Modify the code to fit your specific needs. Add custom transformations or integrate with your existing systems.

Deploy Anywhere

Your Server
Docker
Cloud

Simple and Powerful API

Image Operations

GET

/images/resize/:path

Resize and transform an image with various parameters

Query Parameters:

  • width - Target width
  • height - Target height
  • format - Output format (webp, jpeg, png, avif)
  • quality - Output quality (1-100)
  • rotate, flip, grayscale, etc.
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"

OpenAPI Documentation

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.

http://localhost:3000/swagger

Interactive API Documentation

Explore endpoints, test requests, and view response schemas

Features:

  • Interactive API explorer
  • Request/response schema documentation
  • Try-it-out functionality
  • OpenAPI 3.0 specification
  • Authentication support
  • Downloadable API specification

Official SDK v1.1.1

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
});

@karnak19/resize-it-sdk

Our official SDK makes it easy to integrate Resize-it into your applications. Available for JavaScript and TypeScript projects.

Installation

npm install @karnak19/resize-it-sdk@1.1.1
# or
bun install @karnak19/resize-it-sdk@1.1.1

Features

  • Type-safe API with TypeScript support
  • URL builder for all transformation options
  • Image upload functionality
  • Automatic error handling and retries
  • Lightweight with zero dependencies

SDK Documentation

ResizeIt Class

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) {
    // ...
  }
}

Configuration

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'
});

uploadImage()

Upload an image to the Resize-it service. Supports Buffer, Blob, or base64 string inputs.

Parameters:

  • imageData: Buffer | Blob | string - The image data to upload
  • options: UploadOptions - Upload configuration options

Returns:

Promise<UploadResponse> - A promise resolving to the upload response

Example:

// 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

getResizeUrl()

Generate a URL for a resized version of an image with the specified options.

Parameters:

  • imagePath: string - Path to the image on the server
  • options: ResizeOptions - Resize configuration options

Returns:

string - The URL to the resized image

Example:

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);

getResizedImage()

Fetch a resized image directly as a Blob, useful for further processing or displaying in the browser.

Parameters:

  • imagePath: string - Path to the image on the server
  • options: ResizeOptions - Resize configuration options

Returns:

Promise<Blob> - A promise resolving to the image blob

Example:

// 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;

Resize Options

The SDK supports all transformation options available in the Resize-it API.

Available Options:

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)

Advanced Usage Examples

// 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;
  }
}

Installation Guide

Prerequisites

Before installing Resize-it, make sure you have the following:

Standard Installation

Clone the Repository

git clone https://github.com/karnak19/resize-it.git
cd resize-it

Install Dependencies

bun install
# Or if you prefer npm
npm install

Configure Environment

cp .env.example .env
nano .env  # Edit with your configuration

See the Configuration Options table for available settings.

Start the Server

bun run dev  # Development mode with hot reload
# or
bun run start  # Production mode

The server will start at http://localhost:3000 by default.

Docker Installation

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

Docker Compose

For a complete setup with MinIO and Dragonfly:

wget https://raw.githubusercontent.com/karnak19/resize-it/main/docker-compose.yml
docker-compose up -d

Configuration Options

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

Ready to Optimize Your Images?

Join the community of developers who trust Resize-it v1.1.1 for their image processing needs.