-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (44 loc) · 1000 Bytes
/
main.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"os"
"github.com/MaestroError/go-libheif"
)
func main() {
if len(os.Args) < 4 {
fmt.Printf("Usage: %s [heic|avif|jpeg|png] input_file output_file\n", os.Args[0])
Shutdown()
}
inputFormat := os.Args[1]
inputFile := os.Args[2]
outputFile := os.Args[3]
switch inputFormat {
case "heic", "avif":
// Determine the output format based on the output file extension
switch outputFile[len(outputFile)-3:] {
case "jpg", "peg":
err := libheif.HeifToJpeg(inputFile, outputFile, 100)
if err != nil {
fmt.Println(err)
}
case "png":
err := libheif.HeifToPng(inputFile, outputFile)
if err != nil {
fmt.Println(err)
}
default:
fmt.Println("Unsupported output format")
}
case "jpg", "peg", "jpeg", "png":
err := libheif.ImageToHeif(inputFile, outputFile)
if err != nil {
fmt.Println(err)
}
default:
fmt.Println("Unsupported input format")
}
}
func Shutdown() {
fmt.Println("Created by MaestroError")
os.Exit(1)
}