commit e6084b182a894c69dea9546b351db1d5c45409ac Author: Florian Date: Thu Dec 7 14:43:07 2017 +0100 New Wiki page diff --git a/Quiet-Zones.md b/Quiet-Zones.md new file mode 100644 index 0000000..76b4eec --- /dev/null +++ b/Quiet-Zones.md @@ -0,0 +1,36 @@ +The library doesn't take care of the quiet zones which are required by some barcode types. +You use the following wrapper to create a quiet zone: + +```golang +type QuietZone struct { + width int + barcode barcode.Barcode +} + +func (qz QuietZone) At(x, y int) color.Color { + bounds := qz.barcode.Bounds() + w := bounds.Dx() + h := bounds.Dy() + if x < qz.width || x >= w+qz.width || y < qz.width || y >= h+qz.width { + return color.White + } + return wb.barcode.At(x-qz.width, y-qz.width) +} + +func (qz QuietZone) Bounds() image.Rectangle { + b := qz.barcode.Bounds() + return image.Rect(0, 0, b.Dx()+2*qz.width, b.Dy()+2*qz.width) +} + +func (qz QuietZone) ColorModel() color.Model { + return qz.barcode.ColorModel() +} + +func Main() { + bc, _ := qr.Encode("Foobar", qr.L, qr.Auto) + + var img image.Image = QuietZone{10, bc} + + png.Encode(file, img) +} +``` \ No newline at end of file