qrlogo icon indicating copy to clipboard operation
qrlogo copied to clipboard

why logo is black

Open banbo opened this issue 9 years ago • 5 comments

i put a yellow logo,but get a black one

banbo avatar Jun 25 '16 07:06 banbo

Hi @banbo. Honestly, I've never thought of making logo colorful, it's black and white by design. But I see no problem in (optionally) preserving the color, so will take a look on it soon.

divan avatar Jun 26 '16 15:06 divan

Any solution for this issue?

priyeshpc avatar Oct 27 '20 10:10 priyeshpc

I tried to change the color in your code but still it fails

affkjuhyt avatar May 08 '21 03:05 affkjuhyt

I tried to change the color in your code but still it fails

I tried using his library to rewrite a piece of code in it to be able to print the color of the logo

func (e Encoder) Encode(str string, logo image.Image, size int) (*bytes.Buffer, error) {
	var buf bytes.Buffer

	code, err := qr.New(str, e.QRLevel)
	if err != nil {
		return nil, err
	}

	img := code.Image(size)
	cimg := image.NewRGBA(img.Bounds())
	e.overlayLogo(img, logo, cimg)

	err = png.Encode(&buf, cimg)
	if err != nil {
		return nil, err
	}

	return &buf, nil
}

// overlayLogo blends logo to the center of the QR code,
// keep all colors
func (e Encoder) overlayLogo(dst, src image.Image, cimg draw.Image) {
	draw.Draw(cimg, dst.Bounds(), dst, image.Point{}, draw.Over)
	offset := dst.Bounds().Max.X/2 - src.Bounds().Max.X/2
	for x := 0; x < src.Bounds().Max.X; x++ {
		for y := 0; y < src.Bounds().Max.Y; y++ {
			r, g, b, alpha := src.At(x, y).RGBA()
			cimg.Set(x+offset, y+offset, color.RGBA{R: uint8(r), G: uint8(g), B: uint8(b), A: uint8(alpha)})
		}
	}
}

affkjuhyt avatar May 13 '21 08:05 affkjuhyt

implemented qr-codes with color logo in my fork https://github.com/delivery-club/qrlogo

peakle avatar May 24 '22 14:05 peakle