Generating thumbnails for webp file format

The following code is to create a thumbnail using package
works well for typical image format like jpeg, but it does not work well for webp file format.

I got errorimaging: unsupported image format with the code below.

Is there a more robust way to generate thumbnails for typical image types (jpg, gif, tiff, bmp, etc.) and webp?

package main

import (

func main() {
	//img, _ := imaging.Open("ml/input/apple.jpg")

	// Load webp
	data, _ := ioutil.ReadFile("ml/input/waterski2.webp")
	// Decode webp
	img, _ := webp.Decode(bytes.NewReader(data))
	//Create thumbnail
	dstImage := imaging.Thumbnail(img, 400, 400, imaging.Lanczos)

	err1:=imaging.Save(dstImage, "ml/output/waterski2.webp")
	if err1!=nil{

As far as I understand the WEBP format is not supported in Go yet. I ended up making calls to an external program dwebp (linux) to convert from WEBP to JPG or PNG. It can probably be used in the other direction too. I am confident that a similar program exists on Windows or Mac.

What about this?

If decoding is available, encoding should not be impossible.

Yeah, you might be correct. I don’t know enough about encoding/decoding image formats, to say whether or not this package is usable for conversion.

In my defense though, it looks like that is version 0.0.0, published a week or so ago, so I was not aware of it :slight_smile:

I will definitely look into it for my project, whenever I have time. If it helps the @jack1234 or not, I don’t know.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.