A simple Express.js API that converts images to square format by adding transparent padding.
- Node.js (v14 or higher)
- npm or yarn
- Clone the repository:
git clone <your-repo-url>
cd image-squarer
- Install dependencies:
npm install
The server runs on port 3000 by default. To change the port, set the PORT
environment variable or modify the index.js
file accordingly:
Start the server:
npm start
The API will be available at http://localhost:3000
(or your configured port).
Run the example use-case provided:
node test.js
This will execute the test case to verify the image squaring functionality.
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
Health check endpoint that returns "Image Squarer API is running."
Using curl:
curl -X POST -F "[email protected]" http://localhost:3000/square --output squared-image.png
Using Postman:
- Create a POST request to
http://localhost:3000/square
- Set body to form-data
- Add a key named "image" and select a file
- Send the request
Future enhancements planned for the Image Squarer API:
- Custom background color option (instead of transparent)
- Custom padding color
- Custom output dimensions
- Aspect ratio preservation options
- Image quality/compression settings
- Batch processing multiple images
- Support for additional image formats (WebP, AVIF)
- Image optimization options
- Custom padding on specific sides
- Image resizing before squaring
- Rate limiting
- API key authentication
- Request validation improvements
- Detailed error responses
- API documentation with Swagger/OpenAPI
- Caching layer
- CDN integration
- Docker containerization
- CI/CD pipeline
- Performance monitoring
This project is licensed under the MIT License - see the LICENSE file for details.