boombuler / barcode

a barcode creation lib for golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error about Scale function

sharekte opened this issue · comments

Hi
I got an error when resize barcode which is can not scale barcode to an image smaller than 244x1,I paste the code as blow
`
content:="hello code128"

barcodePic, err := code128.Encode(content)

if err != nil {

	return  err

}

codePic, err := barcode.Scale(barcodePic, 200, 30)

if err != nil {

	return  err

}

file, err := os.Create("sample.png")

if err != nil {

	return err

}

defer file.Close()

err = png.Encode(file, codePic)

if err != nil {

	return  err

}

`
Pls help to check it
Thanks a lot

Hi,

the generated barcode takes 244 spaces and bars) if you scale it to 200 pixels width, there is only about 0.8 pixels per line and the scale function won't let you have line widths below one pixel. If you wan't subpixel rendering please have a look at some image processing libs.

Let me know iff this helps you

Hi boombuler
I've resolved problem and is it possible to ceil factor

func scale1DCode(bc Barcode, width, height int) (Barcode, error) {
	orgBounds := bc.Bounds()
	orgWidth := orgBounds.Max.X - orgBounds.Min.X
	factor := int(float64(width) / float64(orgWidth))
	if factor <= 0 {
		return nil, fmt.Errorf("can not scale barcode to an image smaller than %dx1", orgWidth)
	}

Thanks

Hi,

this will most likely result in not scannable barcodes. Therefore I will not change this.