加入二維碼生成功能
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
@@ -3,6 +3,16 @@ import json
|
||||
import os
|
||||
import re
|
||||
|
||||
from PIL import Image, ImageDraw,ImageFont
|
||||
from barcode import Code128
|
||||
from barcode.writer import ImageWriter
|
||||
import qrcode
|
||||
# 定义图像大小和条形码大小
|
||||
image_width = 2479
|
||||
image_height = 3508
|
||||
qrcode_size = 400
|
||||
|
||||
|
||||
def search_save_and_return(sn):
|
||||
begin_url="https://pro-psurf-app.glb.inc.hp.com/partsurferapi/Search/GenericSearch/"+sn+"/country/CN/usertype/EXT"
|
||||
headers = {
|
||||
@@ -44,7 +54,7 @@ def search_save_and_return(sn):
|
||||
|
||||
|
||||
|
||||
print("HP partsurfer get BuildId and FeatureByte. V0.9")
|
||||
print("HP partsurfer auto get BuildId and FeatureByte. V1.9")
|
||||
print("compiled by kevin. wuwenfengmi@outlook.com")
|
||||
print("for learning purposes only")
|
||||
if not os.path.exists("database/"):
|
||||
@@ -78,24 +88,183 @@ while while_loop:
|
||||
unit_data=jdata['Body']['SerialNumberBOM']['unit_configuration']
|
||||
for i in unit_data:
|
||||
if i['part_number'].lower()=="IMG_BuildId".lower():
|
||||
print("Build Id: "+str(i['part_description']).replace("BID=",""))
|
||||
bilid=str(i['part_description']).replace("BID=","")
|
||||
if i['part_number'].lower()=="IMG_Desc1".lower():
|
||||
Desc1=i['part_description']
|
||||
if i['part_number'].lower()=="IMG_Desc2".lower():
|
||||
Desc2=i['part_description']
|
||||
FeatureByte=Desc1+Desc2
|
||||
FeatureByte=str(FeatureByte).replace(" ","")
|
||||
print("Build Id: "+bilid)
|
||||
print("Feature Byte: "+FeatureByte)
|
||||
#print("Feature Byte 4: ")
|
||||
fb2=""
|
||||
index=0
|
||||
for i in FeatureByte:
|
||||
if index==4:
|
||||
index=0
|
||||
print(" ",end="")
|
||||
#print(" ",end="")
|
||||
fb2+=" "
|
||||
index+=1
|
||||
print(i,end="")
|
||||
|
||||
#print(i,end="")
|
||||
fb2+=i
|
||||
|
||||
print(fb2)
|
||||
print("\n------------------------------------------------\n\n")
|
||||
|
||||
#cp
|
||||
# 创建一个空白图像
|
||||
image = Image.new("RGB", (image_width, image_height), (255, 255, 255))
|
||||
draw = ImageDraw.Draw(image)
|
||||
|
||||
# 条形码配置
|
||||
barcode_options = {
|
||||
"writer": ImageWriter(),
|
||||
"output": 'temp', # 输出格式,可以是文件名或字节流
|
||||
}
|
||||
|
||||
|
||||
|
||||
# 在图像上生成多个条形码并放置它们
|
||||
x_position = 50
|
||||
y_position = 50
|
||||
|
||||
# 加载自定义图片并将其添加到图像中
|
||||
custom_image = Image.open("favicon.png") # 替换为你自己的图片路径
|
||||
image.paste(custom_image, (x_position, y_position))
|
||||
|
||||
y_position+=150
|
||||
|
||||
# 在条形码下方添加自定义文本
|
||||
text_color = (0, 0, 0) # 文本颜色(黑色)
|
||||
# 设置字体大小
|
||||
font_size = 20
|
||||
font_20 = ImageFont.truetype("fonts/arial", font_size) # 替换为你自己的字体文件路径
|
||||
# 创建一个Draw对象并将文本添加到图像上
|
||||
text_draw = ImageDraw.Draw(image)
|
||||
text_draw.text((x_position, y_position), "HP partsurfer auto get BuildId and FeatureByte. V1.9\ncompiled by kevin. wuwenfengmi@outlook.com", fill=text_color, font=font_20)
|
||||
|
||||
y_position+=200
|
||||
|
||||
|
||||
# 在条形码下方添加自定义文本
|
||||
text_color = (0, 0, 0) # 文本颜色(黑色)
|
||||
# 设置字体大小
|
||||
font_size = 50
|
||||
font = ImageFont.truetype("fonts/arial", font_size) # 替换为你自己的字体文件路径
|
||||
# 创建一个Draw对象并将文本添加到图像上
|
||||
text_draw = ImageDraw.Draw(image)
|
||||
text_draw.text((x_position, y_position), "Serial No: "+sn, fill=text_color, font=font)
|
||||
|
||||
y_position+=50
|
||||
|
||||
# 生成条形码
|
||||
barcode = Code128(sn, writer=barcode_options["writer"])
|
||||
barcode_file = barcode.save(barcode_options["output"])
|
||||
# 打开生成的条形码图像
|
||||
barcode_image = Image.open(barcode_file)
|
||||
# 将条形码添加到图像上
|
||||
image.paste(barcode_image, (x_position, y_position))
|
||||
|
||||
# 更新下一个条形码的位置
|
||||
y_position += 400
|
||||
|
||||
|
||||
# 创建一个Draw对象并将文本添加到图像上
|
||||
text_draw = ImageDraw.Draw(image)
|
||||
text_draw.text((x_position, y_position), "Product No: "+pn, fill=text_color, font=font)
|
||||
|
||||
y_position+=50
|
||||
|
||||
# 生成条形码
|
||||
barcode = Code128(pn, writer=barcode_options["writer"])
|
||||
barcode_file = barcode.save(barcode_options["output"])
|
||||
# 打开生成的条形码图像
|
||||
barcode_image = Image.open(barcode_file)
|
||||
# 将条形码添加到图像上
|
||||
image.paste(barcode_image, (x_position, y_position))
|
||||
|
||||
# 更新下一个条形码的位置
|
||||
y_position += 400
|
||||
|
||||
|
||||
# 创建一个Draw对象并将文本添加到图像上
|
||||
text_draw = ImageDraw.Draw(image)
|
||||
text_draw.text((x_position, y_position), "Device Name: "+dn, fill=text_color, font=font)
|
||||
|
||||
y_position+=50
|
||||
|
||||
# 生成二维码
|
||||
qr = qrcode.QRCode(
|
||||
version=1,
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
||||
box_size=10,
|
||||
border=4,
|
||||
)
|
||||
qr.add_data(dn)
|
||||
qr.make(fit=True)
|
||||
qr_image = qr.make_image(fill_color="black", back_color="white").resize((qrcode_size, qrcode_size))
|
||||
# 将二维码添加到图像上
|
||||
image.paste(qr_image, (x_position, y_position))
|
||||
|
||||
# 更新下一个条形码的位置
|
||||
y_position += 600
|
||||
|
||||
|
||||
|
||||
# 创建一个Draw对象并将文本添加到图像上
|
||||
text_draw = ImageDraw.Draw(image)
|
||||
text_draw.text((x_position, y_position), "Build Id: "+bilid, fill=text_color, font=font)
|
||||
|
||||
y_position+=50
|
||||
|
||||
# 生成二维码
|
||||
qr = qrcode.QRCode(
|
||||
version=1,
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
||||
box_size=10,
|
||||
border=4,
|
||||
)
|
||||
qr.add_data(bilid)
|
||||
qr.make(fit=True)
|
||||
qr_image = qr.make_image(fill_color="black", back_color="white").resize((qrcode_size, qrcode_size))
|
||||
# 将二维码添加到图像上
|
||||
image.paste(qr_image, (x_position, y_position))
|
||||
|
||||
# 更新下一个条形码的位置
|
||||
y_position += 600
|
||||
|
||||
# 创建一个Draw对象并将文本添加到图像上
|
||||
text_draw = ImageDraw.Draw(image)
|
||||
text_draw.text((x_position, y_position), "Feature Byte: "+fb2, fill=text_color, font=font)
|
||||
|
||||
y_position+=50
|
||||
|
||||
# 生成二维码
|
||||
qr = qrcode.QRCode(
|
||||
version=1,
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
||||
box_size=10,
|
||||
border=4,
|
||||
)
|
||||
qr.add_data(FeatureByte)
|
||||
qr.make(fit=True)
|
||||
qr_image = qr.make_image(fill_color="black", back_color="white").resize((qrcode_size, qrcode_size))
|
||||
# 将二维码添加到图像上
|
||||
image.paste(qr_image, (x_position, y_position))
|
||||
|
||||
# 更新下一个条形码的位置
|
||||
y_position += 400
|
||||
|
||||
# 创建一个Draw对象并将文本添加到图像上
|
||||
text_draw = ImageDraw.Draw(image)
|
||||
text_draw.text((x_position, y_position), FeatureByte, fill=text_color, font=font)
|
||||
# 保存生成的图像
|
||||
#image.save("barcodes.png")
|
||||
|
||||
# 显示图像(可选)
|
||||
image.show()
|
||||
|
||||
except:
|
||||
print("Data Error")
|
||||
else:
|
||||
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 8.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg
|
||||
PUBLIC '-//W3C//DTD SVG 1.1//EN'
|
||||
'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="25.280mm" height="23.764mm">
|
||||
<!--Autogenerated with python-barcode 0.15.1-->
|
||||
<g id="barcode_group">
|
||||
<rect width="100%" height="100%" style="fill:white"/>
|
||||
<rect x="2.540mm" y="1.000mm" width="0.400mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="3.140mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="3.740mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="4.740mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="5.340mm" y="1.000mm" width="0.600mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="6.340mm" y="1.000mm" width="0.400mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="6.940mm" y="1.000mm" width="0.400mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="7.740mm" y="1.000mm" width="0.600mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="8.740mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="9.140mm" y="1.000mm" width="0.400mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="9.940mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="10.340mm" y="1.000mm" width="0.600mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="11.340mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="11.940mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="12.340mm" y="1.000mm" width="0.400mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="13.540mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="13.940mm" y="1.000mm" width="0.800mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="15.140mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="15.740mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="16.740mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="17.340mm" y="1.000mm" width="0.400mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="17.940mm" y="1.000mm" width="0.400mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="18.740mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="19.740mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="20.140mm" y="1.000mm" width="0.400mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="21.140mm" y="1.000mm" width="0.600mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="21.940mm" y="1.000mm" width="0.200mm" height="15.000mm" style="fill:black;"/>
|
||||
<rect x="22.340mm" y="1.000mm" width="0.400mm" height="15.000mm" style="fill:black;"/>
|
||||
<text x="12.640mm" y="21.000mm" style="fill:black;font-size:10pt;text-anchor:middle;">123asd</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.1 KiB |
@@ -0,0 +1,71 @@
|
||||
from PIL import Image, ImageDraw,ImageFont
|
||||
from barcode import Code128
|
||||
from barcode.writer import ImageWriter
|
||||
import qrcode
|
||||
|
||||
# 定义图像大小和条形码大小
|
||||
image_width = 2479
|
||||
image_height = 3508
|
||||
qrcode_size = 250
|
||||
# 创建一个空白图像
|
||||
image = Image.new("RGB", (image_width, image_height), (255, 255, 255))
|
||||
draw = ImageDraw.Draw(image)
|
||||
|
||||
# 条形码配置
|
||||
barcode_options = {
|
||||
"writer": ImageWriter(),
|
||||
"output": 'temp', # 输出格式,可以是文件名或字节流
|
||||
}
|
||||
|
||||
# 在图像上生成多个条形码并放置它们
|
||||
x_position = 50
|
||||
y_position = 50
|
||||
|
||||
|
||||
# 生成条形码
|
||||
barcode = Code128("test", writer=barcode_options["writer"])
|
||||
barcode_file = barcode.save(barcode_options["output"])
|
||||
|
||||
# 打开生成的条形码图像
|
||||
barcode_image = Image.open(barcode_file)
|
||||
|
||||
# 将条形码添加到图像上
|
||||
image.paste(barcode_image, (x_position, y_position))
|
||||
|
||||
# 更新下一个条形码的位置
|
||||
y_position += 120
|
||||
|
||||
# 在条形码下方添加自定义文本
|
||||
custom_text = "Custom Text 123"
|
||||
text_color = (0, 0, 0) # 文本颜色(黑色)
|
||||
# 设置字体大小
|
||||
font_size = 100
|
||||
font = ImageFont.truetype("fonts/arial", font_size) # 替换为你自己的字体文件路径
|
||||
|
||||
# 创建一个Draw对象并将文本添加到图像上
|
||||
text_draw = ImageDraw.Draw(image)
|
||||
text_draw.text((x_position, y_position + 120), custom_text, fill=text_color, font=font)
|
||||
|
||||
# 更新下一个条形码的位置
|
||||
y_position += 220
|
||||
|
||||
|
||||
# 生成二维码
|
||||
qr = qrcode.QRCode(
|
||||
version=1,
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
||||
box_size=10,
|
||||
border=4,
|
||||
)
|
||||
qr.add_data("QR Code Data456")
|
||||
qr.make(fit=True)
|
||||
|
||||
qr_image = qr.make_image(fill_color="black", back_color="white").resize((qrcode_size, qrcode_size))
|
||||
|
||||
# 将二维码添加到图像上
|
||||
image.paste(qr_image, (x_position, y_position))
|
||||
# 保存生成的图像
|
||||
#image.save("barcodes.png")
|
||||
|
||||
# 显示图像(可选)
|
||||
image.show()
|
||||
Reference in New Issue
Block a user