python-barcode
python-barcode copied to clipboard
GS1-128 images are cut-off
We're losing some pixels on the left and some pixels on the right. The payload and image are correct and match, but the number [superficially] looks off.
We're using 0.15.1 (the latest version).
We're using ImageWriter to render. There doesn't seem to be a quick solution to mitigate this given the supported parameters. Any suggestions?
What class of barcode is this (so I can reproduce the example)?
I think we need to calculate the width not only based on the barcode width, but the text width too.
GS1-128, sorry. This seems like the simplest possible payload that I have seen for this mode/class, so maybe the extra parentheticals usually result in freeing up more space at the bottom.
The kludge was to slightly increase the module-width from .2 to .25:
o = {
'module_width': .25,
}
g.write(f, options=o)
Incidentally, why did this affect the font size and barcode height? Note that the codes here are different but of identical length.
(before, after)
Obviously, the proper solution would be to update the image mechanics to use max(barcode image-size, text image-size)
, though I traced through the execution and could not see a straight-forward way of doing this. I tried overriding methods, return values, and module attributes, but couldn't find anything that affected the width (except for passing a module-width options to the write/render). There is probably a simple solution here that affects the overall width or ability to add extra text-padding that I missed.
Prior to updating the module-width, I figured I could always add a newline in the middle of the text, but there was also a chance of negatively affecting the payload.
Which direction would you go?
Also, what are "guards" and what does packed()
do and/or how to use it?