Draw Text Onto an Image in Go

With a single Cloudmersive API key, you can easily implement dozens of our Image Processing & editing operations into your project. Below, ready-to-run code is available to implement the text drawing iteration of our Image API, which will enable you to generate a customized text visual on an image with specific parameters including font, font size, color, and location on the image (using an X/Y axis of pixels).

Node.JS  Python  C#  Java  PHP  Objective-C  Ruby  Apex  C/C++  cURL  Swift  JavaScript  Go
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/image/edit/draw/text"
method := "POST"
payload := strings.NewReader("BaseImageBytes=%3Cbyte%3E&BaseImageUrl=%3Cstring%3E&TextToDraw=%7B%22Text%22%3A%22%3Cstring%3E%22%2C%22FontFamilyName%22%3A%22%3Cstring%3E%22%2C%22FontSize%22%3A%22%3Cdouble%3E%22%2C%22Color%22%3A%22%3Cstring%3E%22%2C%22X%22%3A%22%3Cdouble%3E%22%2C%22Y%22%3A%22%3Cdouble%3E%22%2C%22Width%22%3A%22%3Cdouble%3E%22%2C%22Height%22%3A%22%3Cdouble%3E%22%7D&TextToDraw=%7B%22Text%22%3A%22%3Cstring%3E%22%2C%22FontFamilyName%22%3A%22%3Cstring%3E%22%2C%22FontSize%22%3A%22%3Cdouble%3E%22%2C%22Color%22%3A%22%3Cstring%3E%22%2C%22X%22%3A%22%3Cdouble%3E%22%2C%22Y%22%3A%22%3Cdouble%3E%22%2C%22Width%22%3A%22%3Cdouble%3E%22%2C%22Height%22%3A%22%3Cdouble%3E%22%7D")client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")
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))
}

All you need to do is copy & paste the above code into your project, and include your image file & Cloudmersive API key.

--

--

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.