Skip to content

ilhamnyto/ubersnap-image-processing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Processing API

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.

Features

  • Convert PNG images to JPEG format
  • Resize images to specified dimensions
  • Compress images with adjustable quality

Prerequisites

Installation

  1. Clone the repository:
git clone https://github.com/ilhamnyto/ubersnap-image-processing.git
  1. Navigate to the project directory:
cd ubersnap-image-processing
  1. Install the required dependencies:
go mod tidy

Usage

  1. Start the server:
go run main.go

The server will start running on http://localhost:8000.

  1. 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

Convert Image

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

Resize Image

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

Compress Image

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

Implementation Details

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.

Testing

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.

About

Image Processing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages