@@ -135,6 +135,9 @@ type QRCode struct {
135
135
ForegroundColor color.Color
136
136
BackgroundColor color.Color
137
137
138
+ // Disable the QR Code border.
139
+ DisableBorder bool
140
+
138
141
encoder * dataEncoder
139
142
version qrCodeVersion
140
143
@@ -193,8 +196,6 @@ func New(content string, level RecoveryLevel) (*QRCode, error) {
193
196
version : * chosenVersion ,
194
197
}
195
198
196
- q .encode (chosenVersion .numTerminatorBitsRequired (encoded .Len ()))
197
-
198
199
return q , nil
199
200
}
200
201
@@ -239,8 +240,6 @@ func newWithForcedVersion(content string, version int, level RecoveryLevel) (*QR
239
240
version : * chosenVersion ,
240
241
}
241
242
242
- q .encode (chosenVersion .numTerminatorBitsRequired (encoded .Len ()))
243
-
244
243
return q , nil
245
244
}
246
245
@@ -251,6 +250,9 @@ func newWithForcedVersion(content string, version int, level RecoveryLevel) (*QR
251
250
// The bitmap includes the required "quiet zone" around the QR Code to aid
252
251
// decoding.
253
252
func (q * QRCode ) Bitmap () [][]bool {
253
+ // Build QR code.
254
+ q .encode ()
255
+
254
256
return q .symbol .bitmap ()
255
257
}
256
258
@@ -268,6 +270,9 @@ func (q *QRCode) Bitmap() [][]bool {
268
270
// negative number to increase the scale of the image. e.g. a size of -5 causes
269
271
// each module (QR Code "pixel") to be 5px in size.
270
272
func (q * QRCode ) Image (size int ) image.Image {
273
+ // Build QR code.
274
+ q .encode ()
275
+
271
276
// Minimum pixels (both width and height) required.
272
277
realSize := q .symbol .size
273
278
@@ -296,11 +301,12 @@ func (q *QRCode) Image(size int) image.Image {
296
301
// Map each image pixel to the nearest QR code module.
297
302
modulesPerPixel := float64 (realSize ) / float64 (size )
298
303
for y := 0 ; y < size ; y ++ {
304
+ y2 := int (float64 (y ) * modulesPerPixel )
299
305
for x := 0 ; x < size ; x ++ {
300
- y2 := int (float64 (y ) * modulesPerPixel )
301
306
x2 := int (float64 (x ) * modulesPerPixel )
302
307
303
308
v := bitmap [y2 ][x2 ]
309
+
304
310
if v {
305
311
pos := img .PixOffset (x , y )
306
312
img .Pix [pos ] = fgClr
@@ -368,7 +374,9 @@ func (q *QRCode) WriteFile(size int, filename string) error {
368
374
// encode completes the steps required to encode the QR Code. These include
369
375
// adding the terminator bits and padding, splitting the data into blocks and
370
376
// applying the error correction, and selecting the best data mask.
371
- func (q * QRCode ) encode (numTerminatorBits int ) {
377
+ func (q * QRCode ) encode () {
378
+ numTerminatorBits := q .version .numTerminatorBitsRequired (q .data .Len ())
379
+
372
380
q .addTerminatorBits (numTerminatorBits )
373
381
q .addPadding ()
374
382
@@ -381,7 +389,7 @@ func (q *QRCode) encode(numTerminatorBits int) {
381
389
var s * symbol
382
390
var err error
383
391
384
- s , err = buildRegularSymbol (q .version , mask , encoded )
392
+ s , err = buildRegularSymbol (q .version , mask , encoded , ! q . DisableBorder )
385
393
386
394
if err != nil {
387
395
log .Panic (err .Error ())
0 commit comments