-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun.go
46 lines (40 loc) · 1.44 KB
/
run.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
package sqip
import (
"image"
)
// Run takes a file and primitve related config properties and creates a SVG-based LQIP image.
func Run(file string, workSize, count, mode, alpha, repeat, workers int, background string) (out string, width, height int, err error) {
// Load image
image, err := LoadImage(file)
if err != nil {
return "", 0, 0, err
}
return RunLoaded(image, workSize, count, mode, alpha, repeat, workers, background)
}
//RunLoaded takes an already loaded image and config properties to generate an SVG LQIP
func RunLoaded(image image.Image, workSize, count, mode, alpha, repeat, workers int, background string) (out string, width, height int, err error) {
// Use image-size to retrieve the width and height dimensions of the input image
// We need these sizes to pass to Primitive and to write the SVG viewbox
w, h := ImageWidthAndHeight(image)
// Since Primitive is only interested in the larger dimension of the input image, let's find it
outputSize := largerOne(w, h)
// create primitive
svg, err := Primitive(image, workSize, outputSize, count, mode, alpha, repeat, workers, background)
if err != nil {
return "", 0, 0, err
}
// resize BG to match original
// Ensures agreement between viewBox and actual content
svg = Refit(svg, w, h)
// minify svg
svg, err = Minify(svg)
if err != nil {
return "", 0, 0, err
}
// blur the svg
svg, err = Blur(svg, w, h)
if err != nil {
return "", 0, 0, err
}
return svg, w, h, nil
}