/
makegif.go
63 lines (50 loc) · 1.49 KB
/
makegif.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
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"image"
"image/gif"
"os"
"github.com/carbocation/genomisc/ukbb/bulkprocess"
"github.com/carbocation/pfx"
)
func makeOneGrid(dicomNames []string, outName string, delay int, withTransparency bool) error {
// Fetch the images based on the dicom names and shove them into a map
sortedPngs, err := bulkprocess.FetchGIFComponents(dicomNames, client)
if err != nil {
return pfx.Err(err)
}
imgMap := make(map[string]image.Image)
for k, dicomName := range dicomNames {
imgMap[dicomName] = sortedPngs[k]
}
// Construct our image grid with 4 columns. Assumes 50 images per cardiac
// cycle. Extremely hacky.
newDicomNames, newImageMap, err := bulkprocess.ImageGrid(dicomNames, imgMap, "", nil, 50, 4)
if err != nil {
return pfx.Err(err)
}
// Create the GIF
outGif, err := bulkprocess.MakeOneGIFFromMap(newDicomNames, newImageMap, delay, withTransparency)
if err != nil {
return pfx.Err(err)
}
// Save file
f, err := os.OpenFile(outName, os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
return pfx.Err(err)
}
defer f.Close()
return pfx.Err(gif.EncodeAll(f, outGif))
}
func makeOneGif(pngs []string, outName string, delay int, withTransparency bool) error {
outGif, err := bulkprocess.MakeOneGIFFromPaths(pngs, delay, withTransparency, client)
if err != nil {
return pfx.Err(err)
}
// Save file
f, err := os.OpenFile(outName, os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
return pfx.Err(err)
}
defer f.Close()
return pfx.Err(gif.EncodeAll(f, outGif))
}