Skip to content

Instantly share code, notes, and snippets.

@balthild
Last active July 3, 2019 09:50
Show Gist options
  • Save balthild/e3426033aaf618cc2c5db58779ad4808 to your computer and use it in GitHub Desktop.
Save balthild/e3426033aaf618cc2c5db58779ad4808 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"golang.org/x/image/webp"
"image/png"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
func bullshit(err error) {
if err != nil {
fmt.Println()
fmt.Println("Bullshit!")
panic(err)
}
}
func convert(name string) {
in, err := os.Open(name + ".webp")
bullshit(err)
defer in.Close()
img, err := webp.Decode(in)
bullshit(err)
out, err := os.Create(name + ".png")
bullshit(err)
defer out.Close()
err = png.Encode(out, img)
bullshit(err)
}
func main() {
ex, err := os.Executable()
bullshit(err)
wd := filepath.Dir(ex)
fmt.Println("Directory:", wd)
err = os.Chdir(wd)
bullshit(err)
files, err := ioutil.ReadDir(".")
bullshit(err)
for _, file := range files {
name := file.Name()
ext := filepath.Ext(name)
if ext != ".webp" {
fmt.Println("Not a webp:", name)
continue
}
convert(strings.TrimSuffix(name, ext))
fmt.Println("Converted:", name)
}
fmt.Print("Done. Press any key to continue...")
var fuckGo string
fmt.Scanln(&fuckGo)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment