Léa*_*iot 8 zpl-ii zpl zebra-printers
我想将ZPL指令发送到Zebra打印机(目前为GK420t).我正在打印50mm x 20mm标签.我想在标签的左上角打印一个标识(小~5mm x 5mm图像).
我想知道我应该遵循的步骤.
我一直在阅读和尝试ZPL手册中的一些内容,但我真的不明白它是如何工作的,也找不到一个有效的例子.
看起来我必须首先将图像"加载"到打印机中(在所谓的"存储区域"/ DRAM中?)然后打印它.
该.GRF文件扩展名的手册中提到了很多次.我找不到将.PNG或.BMP图像转换为.GRF文件的工具.我读到.GRF文件是图形图像的ASCII HEX表示......但它并没有帮助我完成工作.
我可以使用"Zebra Setup Utilities","下载字体和图形",选择任何可用的.MMF文件,添加.BMP图片,将其下载[打印机]并打印测试页,在标签上打印徽标.但到目前为止,我无法使用ZPL指令.
我也想知道我应该使用的最佳尺寸是什么,因为我需要在标签上打印~5mm x 5mm的小图像.我打印的图像是40px x 40px图像.另外,如果我必须从原始图像制作一个.GRF文件,该文件的类型应该是什么(.BMP,.PNG,.JPG)?
你能告诉我怎么办吗?
小智 18
听起来你有一些现有的ZPL代码,而你想要做的就是为它添加一个图像.
如果是这种情况,最简单的解决方案可能是转到Labelary在线ZPL查看器,将ZPL粘贴到查看器中,单击"添加图像",然后将要添加的图像上传到ZPL.
这应该通过添加您需要的图像ZPL命令来修改您的ZPL,然后您可以调整位置等.
这是另一种选择:我在 python 中创建了自己的图像到 .GRF 转换器。随意使用它。
from PIL import Image, ImageOps
import re
import itertools
import numpy as np
# Use: https://www.geeksforgeeks.org/round-to-next-greater-multiple-of-8/
def RoundUp(x, multiple_of = 8):
return ((x + 7) & (-1 * multiple_of))
def image2grf(filePath, width = None, height = None, rotate = None):
image = Image.open(filePath).convert(mode = "1")
#Resize image to desired size
if (width != None):
size = (width, height or width)
if (isinstance(size[0], float)):
size = (int(size[0] * image.width), int(size[1] * image.height))
#Size must be a multiple of 8
size = (RoundUp(size[0]), RoundUp(size[1]))
# image.thumbnail(size, Image.ANTIALIAS)
image = image.resize(size)
if (rotate != None):
image = image.rotate(rotate, expand = True)
image_asArray = np.asarray(np.asarray(image, dtype = 'int'), dtype = 'str').tolist()
bytesPerRow = len(image_asArray[0])
nibblesPerRow = bytesPerRow // 4
totalBytes = nibblesPerRow * len(image_asArray)
#Convert image to hex string
hexString = "".join(
format(int("".join(row[i*4:i*4 + 4]), 2) ^ 0xF, "x")
for row in image_asArray
for i in range(nibblesPerRow)
)
#Compose data
data = "~DGimage," + str(totalBytes // 2) + "," + str(nibblesPerRow // 2) + "," + hexString
#Save image
fileHandle = open(r"labelPicture.grf", "w")
fileHandle.write(data)
fileHandle.close()
if __name__ == '__main__':
# image2grf(r"warning.bmp")
image2grf(r"pallet_label_icons.png", rotate = 90)
Run Code Online (Sandbox Code Playgroud)
编辑:我更新了上面的代码以使用我的新转换方法,它可以生成分辨率更高的 GRF 文件