HTTP Implementation of Image Manipulation using Golang and OpenCV
- Installation
- Install latest Golang version (e.g.
go1.21.x
) - Install OpenCV =>
>= 4.7.x
- Install application dependencies
- Run
go mod download
to download dependencies - Run
go mod vendor
to set dependencies into project directory
- Run
- Install latest Golang version (e.g.
- Build Project
- Run
go build .
(the binary output =>go-http-image-manipulation
)
- Run
- Run HTTP Service
- From Source =>
go run server.go
- From Binary =>
./go-http-image-manipulation
- From Source =>
- Unit Tests
- Normal test => run
go test ./...
- Test with coverage result => run
go test ./... -cover
- Test and generate test coverage report (HTML) =>
go test ./... -coverprofile=c.out && go tool cover -html=c.out -o coverage.html
- Test specific package => run
go test {package_name}
- Example:
go test "github.com/vafrcor/go-http-image-manipulation/services"
- Example:
- Test specific package test case => run
go test {package_name} -run {name_of_test}
- Example:
go test "github.com/vafrcor/go-http-image-manipulation/services" -run TestGetEchoRequestScheme
- Example:
- Normal test => run
-
URL:
[POST] http://localhost:9000/image-png-to-jpeg
-
Request
- Content Type:
multipart/form-data
- Fields:
Name Mandatory Description file yes image file ( image/png
) - Content Type:
-
Response
- Content Type:
application/json
- Fields:
Name Type Description message string detailed message (for both success and error) status boolean true
orfalse
data string output path (for preview) -
Examples:
- Success
{ "message": "Ok", "status": true, "data": "http://localhost:9000/static/small-1710681145040310000-100.jpeg" }
- Error
{ "message": "only accept image using specific format (png)", "status": false, "data": null }
- Content Type:
-
URL:
[POST] http://localhost:9000/image-resize
-
Request
- Content Type:
multipart/form-data
- Fields:
Name Mandatory Description file yes image file ( image/png
,image/jpg
,image/jpeg
,image/bmp
)width yes desired width ( in pixel
)height yes desired height ( in pixel
)keep_aspect_ratio no 1
or0
- Content Type:
-
Response
- Content Type:
application/json
- Fields:
Name Type Description message string detailed message (for both success and error) status boolean true
orfalse
data string output path (for preview) - Example:
- Success
{ "message": "Ok", "status": true, "data": "http://localhost:9000/static/medium-1710685243638707000-100.png" }
- Error
{ "message": "only accept image using specific format (png,jpg,jpeg)", "status": false, "data": null }
- Content Type:
-
URL:
[POST] http://localhost:9000/image-compression
-
Request
- Content Type:
multipart/form-data
- Fields:
Name Mandatory Description file yes image file ( image/png
,image/jpg
,image/jpeg
,image/bmp
)quality yes desired quality ( 1 - 100
) - Content Type:
-
Response
- Content Type:
application/json
- Fields:
Name Type Description message string detailed message (for both success and error) status boolean true
orfalse
data string output path (for preview) - Example:
- Success
{ "message": "Ok", "status": true, "data": "http://localhost:9000/static/medium-1710686662823893000-70.jpeg" }
- Error
{ "message": "http: no such file", "status": false, "data": null }
- Content Type:
- GoCV
- OpenCV