程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python generates 128 barcode (code128)

編輯:Python

#-- encoding: utf-8 -- import logging import sys import os import pygame from pygame.locals import * from hubarcode.code128 import Code128Encoder from PIL import Image,ImageDraw,ImageFont

logging.getLogger("code128").setLevel(logging.DEBUG)

logging.getLogger("code128").addHandler(logging.StreamHandler(sys.stdout))

12-80 10-80 10-60 12-60 10-70 12-70 10-70

''' Use huBarcode,pygame and PIL Generate barcode ''' if name == "main":

#1 Generate barcode
text = "068080835AD000D10701014111".upper()
encoder = Code128Encoder(text,options={"ttf_font":"C:/Windows/Fonts/SimHei.ttf","ttf_fontsize":12,

"bottom_border":15,"height":70,"label_border":2}) encoder.save("test.png",bar_width=1)

2 Generate barcode description

pygame.init()
content = u"P07D111140 T07D1111407010 20150321113322"
font = pygame.font.SysFont('SimHei', 10)
ftext = font.render(content, True, (0, 0, 0))
pygame.image.save(ftext, "t.png")

3 Synthesize Chinese characters into bar codes , Generate a new barcode

img = Image.open("test.png")
img_w, img_h = img.size
icon = Image.open("t.png")
icon_w, icon_h = icon.size
icon = icon.resize((icon_w, icon_h), Image.ANTIALIAS)
w = int((img_w - icon_w) / 2)
h = int((img_h - icon_h) / 2)+35
icon = icon.convert("RGBA")
img.paste(icon, (w, h), icon)
img.save(text+".png") </pre> 

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved