skip2 / go-qrcode

:sparkles: QR Code encoder (Go)
http://go-qrcode.appspot.com
MIT License
2.58k stars 335 forks source link

how to adjust the padding when QR output to file #17

Closed jiaohu closed 4 years ago

jiaohu commented 5 years ago

my code

func TestCreateQrCode(t *testing.T) {
    qrcode.WriteFile("http://www.baidu.com", qrcode.Medium, 256, "qr3.png")
}

then i get the answer like this qr3 the white spacing is widely

Cr4psy commented 5 years ago

The padding is due to the quiet zone around the QRCode. It would be great to be able to remove it.

goribun commented 4 years ago

Picture cropping almost 75% is ok when width greater than 300px.

` x0 := int(float32(size) * 0.125) y0 := x0

x1 := int(float32(size) * 0.875)
y1 := x1

    if rgbImg, ok := img.(*image.Paletted); ok {
    subImg := rgbImg.SubImage(image.Rect(x0, y0, x1, y1)).(*image.Paletted) 
} 

`

skip2 commented 4 years ago

This has been fixed in https://github.com/skip2/go-qrcode/pull/24 . Borders are now made the minimum size possible. There's also now an option to disable borders entirely too.