Skip to content

Commit

Permalink
add NewWithWriter constructor to compressed writer (yeqown#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
h44z authored Jul 5, 2023
1 parent b9035dc commit a69e277
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion writer/compressed/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func New(filename string, opt *Option) (qrcode.Writer, error) {
return compressedWriter{fd: fd, option: opt}, nil
}

func NewWithWriter(writeCloser io.WriteCloser, opt *Option) qrcode.Writer {
return compressedWriter{fd: writeCloser, option: opt}
}

func (w compressedWriter) Write(mat qrcode.Matrix) error {
padding := w.option.Padding
blockWidth := w.option.BlockSize
Expand All @@ -46,7 +50,7 @@ func (w compressedWriter) Write(mat qrcode.Matrix) error {

img := image.NewPaletted(
image.Rect(0, 0, width, height),
color.Palette([]color.Color{backgroundColor, foregroundColor}),
[]color.Color{backgroundColor, foregroundColor},
)
bgColor := uint8(img.Palette.Index(backgroundColor))
fgColor := uint8(img.Palette.Index(foregroundColor))
Expand Down

0 comments on commit a69e277

Please sign in to comment.