Skip to content

Commit

Permalink
Feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Aug 30, 2022
1 parent 30f7dd0 commit c072db4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package main

import (
"bytes"
"fmt"
"image/color"
"io"
Expand All @@ -25,7 +24,7 @@ func main() {
return
}
defer f.Close()
io.Copy(f, bytes.NewReader(pic.GeneratePicture()))
io.Copy(f, pic.GeneratePicture())
}
```

Expand Down
6 changes: 3 additions & 3 deletions text2pictrue.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func NewPictureWithBackGround(png *image.RGBA, dpi float64, padding int, fontSiz
return &p
}

func (p *picture) GeneratePicture() []byte {
func (p *picture) GeneratePicture() *bytes.Buffer {
return saveImage(p.rgba)
}

func saveImage(rgba *image.RGBA) []byte {
func saveImage(rgba *image.RGBA) *bytes.Buffer {
b := bytes.NewBuffer(nil)
bf := bufio.NewWriter(b)
if err := png.Encode(bf, rgba); err != nil {
Expand All @@ -118,5 +118,5 @@ func saveImage(rgba *image.RGBA) []byte {
if err := bf.Flush(); err != nil {
return nil
}
return b.Bytes()
return b
}

0 comments on commit c072db4

Please sign in to comment.