-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ashleyprimo/v1.2.1-dev
v1.2.1: Fix Scale + Render of QR codes
- Loading branch information
Showing
5 changed files
with
65 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package qr | ||
|
||
import ( | ||
"github.com/boombuler/barcode" | ||
"image" | ||
"image/color" | ||
) | ||
|
||
type WhiteBorder struct { | ||
width int | ||
barcode barcode.Barcode | ||
} | ||
|
||
func (wb WhiteBorder) At(x, y int) color.Color { | ||
bounds := wb.barcode.Bounds() | ||
w := bounds.Dx() | ||
h := bounds.Dy() | ||
if x < wb.width || x >= w+wb.width || y < wb.width || y >= h+wb.width { | ||
return color.White | ||
} | ||
return wb.barcode.At(x-wb.width, y-wb.width) | ||
} | ||
|
||
func (wb WhiteBorder) Bounds() image.Rectangle { | ||
b := wb.barcode.Bounds() | ||
return image.Rect(0, 0, b.Dx()+2*wb.width, b.Dy()+2*wb.width) | ||
} | ||
|
||
func (wb WhiteBorder) ColorModel() color.Model { | ||
return wb.barcode.ColorModel() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package qr | ||
|
||
import ( | ||
"errors" | ||
"image" | ||
|
||
"github.com/nfnt/resize" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func scale(code image.Image, sizeInt uint) (image.Image, error) { | ||
log.Debugf("Scaling Image") | ||
|
||
// Resize 'image.Image' to requested size | ||
img := resize.Resize(sizeInt, 0, code, resize.NearestNeighbor) | ||
if img != nil { | ||
return img, nil | ||
} else { | ||
return nil, errors.New("Failed to resize image") | ||
} | ||
} |