Skip to content

Latest commit

 

History

History
118 lines (81 loc) · 2.92 KB

File metadata and controls

118 lines (81 loc) · 2.92 KB

ImageResize - Image Resizing API

A modern image resizing service built with Astro and Sharp, providing an API to resize images from URLs.

Features

  • 🚀 Built with Astro for optimal performance
  • 🖼️ Resize images with customizable dimensions
  • 📐 Maintain aspect ratio when only width or height is specified
  • 🔄 Support for multiple formats (JPEG, PNG, WebP)
  • 🎨 Modern, responsive UI
  • ☁️ Ready for deployment on Vercel

API Usage

Endpoint

GET /api/resize

Parameters

Parameter Type Default Description
url string https://picsum.photos/800/600 The image URL to resize
width number 800 Target width (optional)
height number 600 Target height (optional)
format string jpeg Output format (jpeg, png, webp)

Example Usage

# Resize to specific dimensions
curl "http://localhost:4321/api/resize?url=https://picsum.photos/800/600&width=400&height=300"

# Resize width only (maintain aspect ratio)
curl "http://localhost:4321/api/resize?url=https://picsum.photos/800/600&width=400"

# Resize height only (maintain aspect ratio)
curl "http://localhost:4321/api/resize?url=https://picsum.photos/800/600&height=300"

# Convert to PNG
curl "http://localhost:4321/api/resize?url=https://picsum.photos/800/600&width=400&format=png"

# Redirect to original image (no dimensions specified)
curl "http://localhost:4321/api/resize?url=https://picsum.photos/800/600"

Development

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

npm install

Development Server

npm run dev

The application will be available at http://localhost:4321

Build

npm run build

Preview

npm run preview

Deployment

This project is configured for deployment on Vercel with the @astrojs/vercel adapter.

Deploy to Vercel

  1. Push your code to GitHub
  2. Connect your repository to Vercel
  3. Deploy automatically

The API routes will be available as serverless functions on Vercel.

Project Structure

src/
├── pages/
│   ├── index.astro          # Main documentation page
│   ├── take.astro           # Redirect page for backward compatibility
│   └── api/
│       └── resize.ts        # Image resizing API endpoint
├── config/
│   └── screenshot.ts        # Configuration parameters
├── components/              # Astro components (if any)
└── layouts/                 # Layout components (if any)

Technologies Used

License

ISC