/
processor.go
52 lines (41 loc) · 1.04 KB
/
processor.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
51
52
package webp
import (
"fmt"
"github.com/mateussouzaweb/compactor/compactor"
"github.com/mateussouzaweb/compactor/os"
"github.com/mateussouzaweb/compactor/pkg/generic"
)
// Init processor
func Init(options *compactor.Options) error {
return os.NodeRequire("cwebp", "cwebp-bin")
}
// CreateCopy make a WEBP copy of a image file from almost any format
func CreateCopy(source string, destination string, quality int) error {
_, err := os.Exec(
"cwebp",
"-q", fmt.Sprintf("%d", quality),
destination,
"-o", destination+".webp",
)
return err
}
// Transform processor
func Transform(options *compactor.Options, file *compactor.File) error {
err := os.Copy(file.Path, file.Destination)
if err != nil {
return err
}
return nil
}
// Plugin return the compactor plugin instance
func Plugin() *compactor.Plugin {
return &compactor.Plugin{
Namespace: "webp",
Extensions: []string{".webp"},
Init: Init,
Resolve: generic.Resolve,
Related: generic.Related,
Transform: Transform,
Optimize: generic.Optimize,
}
}