-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPortaCLI.go
More file actions
57 lines (54 loc) · 1.19 KB
/
PortaCLI.go
File metadata and controls
57 lines (54 loc) · 1.19 KB
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
51
52
53
54
55
56
57
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
)
func checkExists(filename string) bool {
if _, err := os.Stat(filename); os.IsNotExist(err) {
return false
}
return true
}
func main() {
fmt.Println(startMessage)
flag.Usage = usage
filePtr := flag.String("f", "img.jpg", "")
outputPtr := flag.String("o", "default", "")
vidPtr := flag.Bool("v", false, "")
collagePtr := flag.Bool("collage", false, "")
flag.Parse()
file := *filePtr
if !checkExists(file) {
fmt.Printf("File %s doesn't exists", file)
return
}
ext := filepath.Ext(file)
if ext != ".jpg" {
fmt.Println("Unsupported file extension")
return
}
bName := filepath.Base(file)
kind := "jpg"
if *vidPtr {
kind = "mp4"
}
rName := *outputPtr
if rName == "default" {
rName = fmt.Sprintf("%s_portacli.%s", bName[:len(bName)-len(ext)], kind)
}
pFile, err := createPortrait(file, *collagePtr, *vidPtr)
if err != nil {
fmt.Println("Can't create portrait:", err)
return
}
fmt.Println("OK! Got portrait:", pFile)
fmt.Println("Downloading...")
err = downloadPortrait(rName, pFile)
if err != nil {
fmt.Println("Can't download portrait:", err)
return
}
fmt.Printf("Done! Portrait is saved as %s.", rName)
}