image: move border calculation to calculateSizes().
Dmitry Chestnykh dmitry@codingrobots.com
Fri, 22 Apr 2011 00:05:19 +0200
1 files changed,
9 insertions(+),
11 deletions(-)
jump to
M
image.go
→
image.go
@@ -41,15 +41,7 @@ uint8(rand.Intn(129)),
0xFF, } // Calculate sizes - var border int - if width > height { - border = height / 5 - } else { - border = width / 5 - } - bwidth := width - border*2 - bheight := height - border*2 - img.calculateSizes(bwidth, bheight, len(numbers)) + img.calculateSizes(width, height, len(numbers)) // Draw background (10 random circles of random brightness) img.fillWithCircles(10, img.dotSize) // Randomly position captcha inside the image@@ -83,9 +75,15 @@ }
func (img *CaptchaImage) calculateSizes(width, height, ncount int) { // Goal: fit all numbers inside the image. + var border int + if width > height { + border = height / 5 + } else { + border = width / 5 + } // Convert everything to floats for calculations - w := float64(width) - h := float64(height) + w := float64(width-border*2) + h := float64(height-border*2) // fw takes into account 1-dot spacing between numbers fw := float64(fontWidth) + 1 fh := float64(fontHeight)