https://github.com/iqbaleff214/simple-go-image-processing
Simple Golang backend service with HTTP routes for image processing.
https://github.com/iqbaleff214/simple-go-image-processing
fiber go gocv golang image-processing opencv
Last synced: about 1 month ago
JSON representation
Simple Golang backend service with HTTP routes for image processing.
- Host: GitHub
- URL: https://github.com/iqbaleff214/simple-go-image-processing
- Owner: iqbaleff214
- Created: 2024-03-19T02:21:01.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-20T00:55:09.000Z (over 2 years ago)
- Last Synced: 2025-03-04T18:36:43.372Z (over 1 year ago)
- Topics: fiber, go, gocv, golang, image-processing, opencv
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Image Processor
Golang backend service with HTTP routes for image processing. This service has the following functionalities:
- Convert image files from PNG to JPEG.
- Resize images according to specified dimensions.
- Compress images to reduce file size while maintaining reasonable quality.
## Prerequisite
- This project is built using [**Go version 1.21.0**](https://go.dev/dl/), and it is expected to be developed using this specific version of Golang to ensure the desired outcome.
- Please ensure that OpenCV is installed on your computer, with a minimum version of [**OpenCV 4.7.0**](https://gocv.io/getting-started/).
## How to Run
- Install project dependencies using the command `go mod download`.
- Run the service using the command `go run .` or `go run main.go`.
## How to Build
Execute the following command to build the binary:
```shell
go build -ldflags "-s -w" -o ./out .
```
Then you can run the service using the command `./out`.
## Usage
### [POST] /converter
Convert image file from PNG to JPEG.
#### Request Body
| Name | Required | Type | Description |
| -------------:|:--------:|:-------:| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `image` | required | file | The image file to be converted.
Supported MIME type: `image/png`. |
#### Success response
The response will return an image file if successful.
#### Error response
The response will be returned as JSON in case of an error. For example:
```json
{
"code": 400,
"message": "You have to provide `image` field!",
"status": "error"
}
```
### [POST] /resizer
Resize image according to specified dimensions.
#### Request Body
| Name | Required | Type | Description |
| ----:|:--------:|:----:| ----------- |
| `image` | required | file | The image file to be converted.
Supported MIME type: `image/png` and `image/jpeg`. |
| `width` | required | integer | Width dimension. |
| `height` | required | integer | Height dimension.|
#### Success response
The response will return an image file if successful.
#### Error response
The response will be returned as JSON in case of an error. For example:
```json
{
"code": 400,
"message": "You have to provide `image` field!",
"status": "error"
}
```
### [POST] /compressor
Compress image to reduce file size while maintaining reasonable quality.
#### Request Body
| Name | Required | Type | Description |
| ----:|:--------:|:----:| ----------- |
| `image` | required | file | The image file to be converted.
Supported MIME type: `image/png` and `image/jpeg`. |
#### Success response
The response will return an image file if successful.
#### Error response
The response will be returned as JSON in case of an error. For example:
```json
{
"code": 400,
"message": "You have to provide `image` field!",
"status": "error"
}
```
## Test
Execute the following command to run the tests:
```shell
go test -v .
```
To run the tests with code coverage, execute the following command:
```shell
go test -v -cover .
```
The test coverage is at **84.2%**.