Webp is new and modern format for images which makes images smaller without losing its quality.
Webp also supports animations, and by many reviewers it’s considered as very good alternative to GIF and even APNG
On web you already can find many libraries for converting images to webp and vise versa. I will propose my version as well, but at this time written on Golang. If you already know what is Golang good for you, if not, I suggest read more about it on it’s official page: https://golang.org/
Here is small code snippet to convert GIF animated image to webp animation. It was made possible by importing module: https://github.com/sizeofint/gif-to-webp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
package main import ( "fmt" "io/ioutil" giftowebp "github.com/sizeofint/gif-to-webp" ) func main() { gifBin, _ := ioutil.ReadFile("giphy.gif") converter := giftowebp.NewConverter() converter.LoopCompatibility = false converter.WebPConfig.SetLossless(1) converter.WebPAnimEncoderOptions.SetKmin(9) converter.WebPAnimEncoderOptions.SetKmax(17) webpBin, err := converter.Convert(gifBin) if err != nil { fmt.Println("Convert error:", err) return } ioutil.WriteFile("giphy.webp", webpBin, 0777) fmt.Println("Done!") } |