python - 使用 Treepoem 和 BWIPP (Python) 将额外文本添加到条码
问题描述
我正在使用 treepoem(以及 BWIPP)生成条形码,我希望条形码的编号在下方,其他附加文本在上方。我试图将这一切保留在 eps 文件生成中,而不是以任何其他形式转换/编辑,因为这对于我在生成后对它们所做的事情很重要。
以下是我的代码(我尝试了文档中的各种不同选项,包括alttext
,但均未成功)。我正在使用Python 3.8.2和Treepoem 3.10.0。
import treepoem # for barcode generation
def generate_rlb_barcode(barcode_type, barcode_data, image_name):
eps_image = treepoem.generate_barcode(barcode_type, barcode_data, options={'includetext': True})
print("image generation complete.")
eps_image.convert('L')
print("image converted to monochrome.")
eps_image.save(image_name)
print("image saved as " + str(image_name))
def main():
barcode_image_name = 'test_img'
generate_rlb_barcode('upca', '123456059973', (barcode_image_name + ".eps"))
main()
解决方案
安装 treepoem 包:
pip install treepoem
# or
python -m pip install treepoem
运行此代码
import treepoem
image = treepoem.generate_barcode(
barcode_type="code128", # One of the BWIPP supported codes.
data="Yout text-978316148fsd4100",
options= {"includetext": True}
)
image.convert("1").save("output_qrcode_or_barcode.png")
推荐阅读
- angular - 无法设置值以在反应形式中选择
- html - 使用 ngFor 访问嵌套的 json
- microsoft-dynamics - NAV 2016 中的项目开发是否与 AX 2012 类似?
- javascript - 如何检测一个按钮是否在jquery中被折叠?
- javascript - UUID 的替代品
- weblogic - 如何在不关闭服务器的情况下清除 WebLogic Server 控制台上的日志?
- javascript - 无法在 Vue 模板中显示 JSON 响应数据
- python - 使用 scikit-image 将 png 转换为 jpeg
- mysql - mysql使用变量来决定是否执行插入
- class - 为什么我收到错误消息:“Credis_Client::scan() 的参数 1 应为参考”?