initj
This commit is contained in:
parent
6169bca983
commit
fca2b77d7c
2 changed files with 282 additions and 0 deletions
57
esiconv/main.go
Normal file
57
esiconv/main.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/gif"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/kayteh/esi"
|
||||
)
|
||||
|
||||
func main() {
|
||||
convPath := os.Args[1]
|
||||
outPath := os.Args[2]
|
||||
|
||||
fin, err := os.Open(convPath)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
fout, err := os.OpenFile(outPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
img, _, err := image.Decode(fin)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
fin.Close()
|
||||
|
||||
ext := path.Ext(outPath)
|
||||
switch ext[1:] {
|
||||
case "esi":
|
||||
err = esi.Encode(fout, img)
|
||||
case "png":
|
||||
err = png.Encode(fout, img)
|
||||
case "jpg":
|
||||
fallthrough
|
||||
case "jpeg":
|
||||
err = jpeg.Encode(fout, img, nil)
|
||||
case "gif":
|
||||
err = gif.Encode(fout, img, nil)
|
||||
default:
|
||||
log.Fatalf("extension %s unknown", ext)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
fout.Close()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue