changed initial retrieval to callback due to original's Save() pattern
This commit is contained in:
parent
d8cf23c038
commit
1c31e40d79
1 changed files with 6 additions and 5 deletions
|
@ -23,7 +23,7 @@ func PNG(width, height int) (Renderer, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func InMemory(width, height int) (Renderer, error) {
|
func InMemory(width, height int, cb func(image.Image)) (Renderer, error) {
|
||||||
i := image.NewRGBA(image.Rect(0, 0, width, height))
|
i := image.NewRGBA(image.Rect(0, 0, width, height))
|
||||||
gc, err := drawing.NewRasterGraphicContext(i)
|
gc, err := drawing.NewRasterGraphicContext(i)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -32,6 +32,7 @@ func InMemory(width, height int) (Renderer, error) {
|
||||||
i: i,
|
i: i,
|
||||||
gc: gc,
|
gc: gc,
|
||||||
},
|
},
|
||||||
|
cb,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -245,12 +246,12 @@ func (rr *rasterRenderer) Save(w io.Writer) error {
|
||||||
|
|
||||||
type memRenderer struct {
|
type memRenderer struct {
|
||||||
rasterRenderer
|
rasterRenderer
|
||||||
|
cb func(image.Image)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *memRenderer) Save(w io.Writer) error {
|
func (m *memRenderer) Save(w io.Writer) error {
|
||||||
|
if m.cb != nil {
|
||||||
|
m.cb(m.i)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *memRenderer) AsImage() image.Image {
|
|
||||||
return m.i
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue