Cloudmersive Image Processing API: How to Rotate an Image using Go

Easily adjust the angle of an image by defining an arbitrary degree of rotation (0.0–360.0). This API will support common file formats like PNG & JPEG, and can be implemented into your Go project with the code examples included below in this article.

First, you’ll need an API key — you can easily get one by creating a free account on our website (www.cloudmersive.com). A free account will grant a limit of 800 API calls per month, with access to all Cloudmersive APIs on the Cloudmersive API Console.

package mainimport (
"fmt"
"bytes"
"mime/multipart"
"os"
"path/filepath"
"io"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/image/edit/rotate/%3Cdouble%3E/angle"
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

The top benefits of using Angular for your project

Remix — A Javascript Framework for Modern UX

Character Controller — Part 3: Movement

Array Manipulation in JavaScript

Benefits of AngularJS

How to Extract Macro Information from a Word file in Node.JS

Build frontend page using relay-JS and GraphQL server

How GraphQL Replaces Redux

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

Find the Location of a Symbol in an Image using Go

Part 2: Grpc Proto Code Generation Using Protoc for Message and Services

User Creation And Authentication in Golang Part 1

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