Skip to content

A lightweight Express.js API that automatically converts images to square format by adding transparent padding. Perfect for social media posts, profile pictures, and any application requiring consistent square image dimensions. Features include transparent padding, PNG output, and a simple REST API interface.

License

Notifications You must be signed in to change notification settings

devroy10/image-squarer

Repository files navigation

Image Squarer API

A simple Express.js API that converts images to square format by adding transparent padding.

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn

Installation

  1. Clone the repository:
git clone <your-repo-url>
cd image-squarer
  1. Install dependencies:
npm install

Configuration

The server runs on port 3000 by default. To change the port, set the PORT environment variable or modify the index.js file accordingly:

Running the Server

Start the server:

npm start

The API will be available at http://localhost:3000 (or your configured port).

Testing

Run the example use-case provided:

node test.js

This will execute the test case to verify the image squaring functionality.

API Endpoints

POST /square

Converts an image to square format by adding transparent padding.

Request:

  • Method: POST
  • Content-Type: multipart/form-data
  • Body: Form field named "image" containing the image file

Response:

  • Success: PNG image with transparent padding
  • Error: Error message with appropriate status code

GET /

Health check endpoint that returns "Image Squarer API is running."

Example Usage

Using curl:

curl -X POST -F "[email protected]" http://localhost:3000/square --output squared-image.png

Using Postman:

  1. Create a POST request to http://localhost:3000/square
  2. Set body to form-data
  3. Add a key named "image" and select a file
  4. Send the request

Roadmap

Future enhancements planned for the Image Squarer API:

Image Customization

  • Custom background color option (instead of transparent)
  • Custom padding color
  • Custom output dimensions
  • Aspect ratio preservation options
  • Image quality/compression settings

Advanced Features

  • Batch processing multiple images
  • Support for additional image formats (WebP, AVIF)
  • Image optimization options
  • Custom padding on specific sides
  • Image resizing before squaring

API Enhancements

  • Rate limiting
  • API key authentication
  • Request validation improvements
  • Detailed error responses
  • API documentation with Swagger/OpenAPI

Performance & Infrastructure

  • Caching layer
  • CDN integration
  • Docker containerization
  • CI/CD pipeline
  • Performance monitoring

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A lightweight Express.js API that automatically converts images to square format by adding transparent padding. Perfect for social media posts, profile pictures, and any application requiring consistent square image dimensions. Features include transparent padding, PNG output, and a simple REST API interface.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published