How to Normalize Image Rotation and Remove EXIF Rotation Data in Go

Cloudmersive
2 min readMar 18, 2022

Often when we take photos with our phone cameras, information about the location and orientation of the photo we took is saved as EXIF data within the image file. With our Image API, you can easily normalize the rotation of such images and remove the EXIF data, making them much easier to process. You can easily implement this API into your project with ready-to-run code samples in Go:

Node.JS  Python  C#  Java  PHP  Objective-C  Ruby  Apex  C/C++  cURL  Swift  JavaScript  Go
package main
import (
"fmt"
"bytes"
"mime/multipart"
"os"
"path/filepath"
"io"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/image/edit/auto-orient/remove-exif"
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))
}

You’ll need to input your image file and API key where indicated in the documentation. To get your hands on an API key, head to our website (www.cloudmersive.com) and make an account. There you’ll be able to create a free account zero financial commitments and a limit of 800 API calls per month, or select from other account options.

--

--

Cloudmersive

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