How to Adaptively Adjust Contrast in an Image to be More Appealing to See using Go

Calling our contrast adjustment API will return your image file with a new, specified gamma value. Values between 0 and 1.0 will reduce contrast, and values above 1.0 will increase contrast (2.0 is recommended).

To take advantage of this API for your Golang project, use ready-to-run code included below from our API Console page (Cloudmersive API Console). First, however, you’ll need a Cloudmersive API key — head to our website (www.cloudmersive.com) and create an account to receive one. There is a free account option available with a limit of 800 API calls per month, among other tiered account options.

package mainimport (
"fmt"
"bytes"
"mime/multipart"
"os"
"path/filepath"
"io"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/image/edit/contrast/%3Cdouble%3E/adaptive"
method := "POST"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
file, errFile1 := os.Open("/path/to/file")
defer file.Close()
part1,
errFile1 := writer.CreateFormFile("imageFile",filepath.Base("/path/to/file"))
_, errFile1 = io.Copy(part1, file)
if errFile1 != nil {
fmt.Println(errFile1)
return
}
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "multipart/form-data")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

--

--

--

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Animated Tile Sprites

Polys recognized as the most innovative democratic platform

What to do if every website update causes user complaints

What are Threads in Java ?

Main Thread in Java

Deploy a Load Balancer and Multiple Web Servers on AWS instances through ANSIBLE!

How to Quickly Count All Items in Each Outlook File with VBA

Getting started with automation testing and Nightwatch.js

Significance of “Sat2Farm App” in farm monitoring:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

More from Medium

Detect & Find Faces and Landmarks (Eyes, Nose & Mouth) in an Image using Go

Compare and Match Faces in Go

How to Invert, Negate the Colors in an Image using Go

Scan and Recognize an Image of a Barcode in Go