This is a Go backend service that provides an API for image processing tasks, including converting images to JPEG format, resizing images, and compressing images.
- Convert PNG images to JPEG format
- Resize images to specified dimensions
- Compress images with adjustable quality
- Go (version 1.16 or later)
- Echo web framework
- Imaging library
- Clone the repository:
git clone https://github.com/ilhamnyto/ubersnap-image-processing.git
- Navigate to the project directory:
cd ubersnap-image-processing
- Install the required dependencies:
go mod tidy
- Start the server:
go run main.go
The server will start running on http://localhost:8000
.
- API Endpoints:
- GET / - Healthcheck endpoint
- POST /convert - Convert a PNG image to JPEG format
- POST /resize - Resize an image to specified dimensions
- POST /compress - Compress an image with adjustable quality
POST /convert
Request Body:
file
(multipart/form-data): The PNG image file to be converted.
Example:
curl -X POST "http://localhost:8000/convert" -F "file=@logo.png" > output.jpeg
Request Body:
file
(multipart/form-data): The image file to be resized.width
(query parameter): The desired width for the resized image.height
(query parameter): The desired height for the resized image.
Example:
curl -X POST "http://localhost:8000/resize?width=50&height=50" -F "file=@logo.png" > output.png
POST /compress
Request Body:
file
(multipart/form-data): The image file to be compressed.quality
(query parameter): The desired quality for the compressed image (0-100).
Example:
curl -X POST "http://localhost:8000/compress?quality=80" -F "file=@logo.png" > output.png
The API is implemented using the Echo web framework and the Imaging library for image processing tasks. The server spawns a pool of worker goroutines to handle concurrent image processing requests. The processed images are returned in the response body as JPEG data.
The code utilizes a semaphore-based approach to limit the number of concurrent workers and prevent resource exhaustion. Tasks are enqueued in a buffered channel and picked up by available workers.
To run the test suite, navigate to the project directory and execute the following command:
go test ./test
The test suite includes test cases for various scenarios, such as invalid input parameters and successful image processing operations.