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.
- This project is built using Go version 1.21.0, 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.
- Install project dependencies using the command
go mod download
. - Run the service using the command
go run .
orgo run main.go
.
Execute the following command to build the binary:
go build -ldflags "-s -w" -o ./out .
Then you can run the service using the command ./out
.
Convert image file from PNG to JPEG.
Name | Required | Type | Description |
---|---|---|---|
image |
required | file | The image file to be converted. Supported MIME type: image/png . |
The response will return an image file if successful.
The response will be returned as JSON in case of an error. For example:
{
"code": 400,
"message": "You have to provide `image` field!",
"status": "error"
}
Resize image according to specified dimensions.
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. |
The response will return an image file if successful.
The response will be returned as JSON in case of an error. For example:
{
"code": 400,
"message": "You have to provide `image` field!",
"status": "error"
}
Compress image to reduce file size while maintaining reasonable quality.
Name | Required | Type | Description |
---|---|---|---|
image |
required | file | The image file to be converted. Supported MIME type: image/png and image/jpeg . |
The response will return an image file if successful.
The response will be returned as JSON in case of an error. For example:
{
"code": 400,
"message": "You have to provide `image` field!",
"status": "error"
}
Execute the following command to run the tests:
go test -v .
To run the tests with code coverage, execute the following command:
go test -v -cover .
The test coverage is at 84.2%.