boombuler / barcode

a barcode creation lib for golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Thank you for replying... but my question was unanswered

MichaelLiss opened this issue · comments

Thank you for replying... but which one is correct?

I am new to programming in Go... and could use a little help with this.... (thanks !)

		bytes := []byte("hello world")
		azCode, _ := aztec.Encode(bytes, aztec.DEFAULT_EC_PERCENT, aztec.DEFAULT_LAYERS)
		azCode, _ = barcode.Scale(azCode, 40, 100)

		retval := A or B 

              return retval

So how do I convert the barcode to a byte array?

( I don't need it in a PNG or other image type... I just need a byte string )

A

retval := []byte(azCode.Content())  // is this right????

or

B

retval := []byte(azCode)

// actually go has a problem with this:
// cannot convert azCode (variable of type barcode.Barcode) to []bytecompilerInvalidConversion

Originally posted by @MichaelLiss in #66 (comment)

This seems to work ... but unsure why scaling is failing

						b := []byte("some really long string")
						azCode, _ := aztec.Encode(b, aztec.DEFAULT_EC_PERCENT, aztec.DEFAULT_LAYERS)

						// this fails for some reason ...
						//azCode, _ = barcode.Scale(azCode, 40, 100)

						buf1 := new(bytes.Buffer)
						err := png.Encode(buf1, azCode)
						test := buf1.Bytes()

Hi,

about the byte string: What should be the content of the string?
If you say you need the barcode as byte array: The barcode is a visual representation (an image) but a byte array is some kind of data which can be send or stored. To send or store the barcode you need to specify the format. Could you please clarify your task?

The Content method returns the string which was used to generate the barcode some really long string in your second example.

About the scaling: any error message? The example works fine for me...

It doesn't appear to have any errors when I make the call it simply returns a nill object

BarCodeScaleFail

Scale also returns an error, which you discard ... Maybe that helps

the error message I am getting is that it cannot scale below 49,49,
So I am interested in how this succeeded for you ?

azCode, _ = barcode.Scale(azCode, 40, 100)

Did you do something extra?
Do I need to set something up to scale smaller?

Hi, the sample string resulted in a smaller barcode. Thats the reason. The scale function does not allow scaling below 1px per "barcode block". So you might want to check the size of the resulting Image

So.. create it... scale it ... if it fails scale it again? (loop until sucess?)

what do you want to use it for?

If you just want a larger image, you could just multiply the width and height of the image by factor 10 or so. If you just wan't any image, you dont need to scale it at all. if you really need a 40x100px image you should use another lib to scale the image because the focus of this lib is to create barcodes not to scale images with "subpixel rendering".

Example for 10x larger image:

azCode, _ := aztec.Encode(b, aztec.DEFAULT_EC_PERCENT, aztec.DEFAULT_LAYERS)

factor := 10
width := azCode.Bounds().Dx() * factor
height := azCode.Bounds().Dy() * factor

azCode, _ = barcode.Scale(azCode, width, height)

I hear what you're saying... but having a "scale" function implies scaling to what ever I need ... ?

Retrospectively I should never have included the scale function because it causes so many issues. But even if it would scale to any resolution, I highly doubt that you could ever scan that image with any scanner... I might improve the documentation for it...