-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_util.go
More file actions
53 lines (48 loc) · 1 KB
/
image_util.go
File metadata and controls
53 lines (48 loc) · 1 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
package main
import (
"image"
_ "image/gif"
_ "image/jpeg"
"os"
"github.com/e2u/goboot"
)
var (
cssKeyWork = []string{
`!`, `"`, `#`, `$`, `%`, `&`,
`\`, `(`, `)`, `*`, `+`, `,`,
`.`, `/`, `:`, `;`, `<`, `~`,
`=`, `>`, `?`, `@`, `[`, `\`,
`]`, `^`, "`", `{`, `|`, `}`, `-`}
)
type SpriteImage struct {
Width int
Height int
Format string
Image image.Image
FileName string
}
// 读取多个图片文件并返回 SpriteImage 数组
func NewSpriteImageFromFiles(files []string) []*SpriteImage {
var sis []*SpriteImage
for _, file := range files {
f, err := os.Open(file)
if err != nil {
goboot.Log.Errorf("open file error: %v", err.Error())
continue
}
defer f.Close()
i, format, err := image.Decode(f)
if err != nil {
goboot.Log.Errorf("decode image %v error: %v", file, err.Error())
continue
}
sis = append(sis, &SpriteImage{
Format: format,
Image: i,
Width: i.Bounds().Max.X,
Height: i.Bounds().Max.Y,
FileName: file,
})
}
return sis
}