boombuler / barcode

a barcode creation lib for golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resize code128 barcodes?

zihaoyu opened this issue · comments

Does this library support resizing code128 barcodes? I didn't find any in GoDoc. Thanks!

Hi,

once you have generated a barcode (code128 or anything else), you can use the Scale function to resize it.
The scale function itself is a very simple approach but since all barcode implement the image interface all other golang libs which support image resizing should work.

I hope this helps you. Please let me know.

Thanks @boombuler . Yes the Scale() function worked.

code, _ := code128.Encode("1709462")
scaledCode, _ := barcode.Scale(code, 300, 100)
file, _ := os.Create("barcode.png")
defer file.Close()

png.Encode(file, scaledCode)

The built in function Scale adds white space both left and right
when the width cannot be reached (because the boundary box
is already reached by reaching the height limit).

But that white space cannot be removed anymore, because
one does not know how much was added by the Scale function.

Is that white space required? Can it be made optional?

The problem is that this white space makes it difficult
to align this images on other surfaces.

@nicolasfranck the scale function scales the barcode to the largest multiple of the original size and then add white space until the desired size is reached, if you need a more sophisticated approach you should use an imageprocessing lib to scale the barcode.

@boombuler as I thought. It is more "shaving" than "scaling" that I need to remove those borders ;-)