-
Notifications
You must be signed in to change notification settings - Fork 0
/
manipulator.go
48 lines (38 loc) · 955 Bytes
/
manipulator.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
package main
import (
"github.com/nfnt/resize"
"image"
"io"
)
type Manipulator interface {
Format() string
Bounds() image.Rectangle
Resize(uint, uint)
Save(io.Writer) error
}
type NewManipulator func(io.ReadSeeker, string, image.Image) (Manipulator, error)
type Saver func(io.Writer, image.Image) error
type GenericManipulator struct {
image image.Image
saver Saver
format string
}
func NewGenericManipulator(image image.Image, format string, saver Saver) Manipulator {
return &GenericManipulator{
image: image,
saver: saver,
format: format,
}
}
func (m *GenericManipulator) Format() string {
return m.format
}
func (m *GenericManipulator) Bounds() image.Rectangle {
return m.image.Bounds()
}
func (m *GenericManipulator) Resize(width, height uint) {
m.image = resize.Resize(width, height, m.image, resize.NearestNeighbor)
}
func (m *GenericManipulator) Save(writer io.Writer) error {
return m.saver(writer, m.image)
}