🚨 rethumb will shutdown on September 4th, 2021 🚨 (Twitter)

<< More Tutorials

How to convert an image to JPG, GIF, PNG, TIF or WebP in Go using rethumb?

To convert an image to JPG, GIF, PNG, TIF or WebP in Go use the following code:

package main

import (

func main() {
	// First apply a square operation, then convert to PNG format.

	paramOperation1 := "square";
	paramValue1 := "100";

	paramOperation2 := "format";
	paramValue2 := "png"; // Other formats available: jpg, gif, tiff and webp..

	imageURL := "http://images.rethumb.com/image_coimbra_600x300.jpg";
	imageFilename := "resized-image.jpg";

	resp, err := http.Get(fmt.Sprintf("http://api.rethumb.com/v1/%s/%s/%s/%s/%s", paramOperation1, paramValue1, paramOperation2, paramValue2, imageURL))
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)

	err = ioutil.WriteFile(imageFilename, body, 0644)

func check(e error) {
	if e != nil {

Start using this example now

Use the following commands to get started:

$ git clone https://github.com/rethumb/rethumb-go-examples.git
$ cd rethumb-go-examples
$ go build format.go
$ ./format

More examples using Go