用于创建 .TMB 图像的库?

发布于 2024-09-26 08:35:04 字数 68 浏览 4 评论 0原文

有谁知道适合以 .TMB 格式写入图像的库?

.TMB 格式适合从 Epson 热敏收据打印机打印徽标。

Is anyone aware of a library suitable for writing an image in .TMB format?

The .TMB format is suitable for printing logos from a Epson thermal receipt printer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉黛浅 2024-10-03 08:35:05

经过大约一个小时左右的查看二进制数据后,我得出以下结论:

*.TMB 图像实际上只是一个用于打印光栅图像的序列化 ESC/POS 命令。

使用以下命令:

od -ta -v [YOUR_TMB_FILE] | head

我们可以在 TMB 文件的开头查看二进制数据,即 ASCII 字符数据。

我有一个看起来像这样的文件:

0000000  gs   v   0 nul   5 nul   P nul del del del del del del del del
0000020 del del del del del del del del del del del del del del del del
... snipped for brevity ...

根据 ESC/POS编程指南,打印光栅图像的ASCII命令是:

GS V 0

嗯..有趣!

一时兴起,我决定将 5P 转换为其十进制等值,分别为 5380 ,我的 .TMB 图像的确切尺寸(实际上是 80x53)!

此后一切都水到渠成。 .TMB 文件的其余部分只是二进制图像数据。

这是我为了测试我的理论而编写的一次性 Python 脚本:

  1 out = open('test.TMB', 'wb')
  2 
  3 width = 80
  4 height = 53
  5 
  6 NUL = chr(0)
  7 GS = chr(29)
  8 V = chr(118)
  9 ZERO = chr(48)
 10 
 11 W = chr(width)
 12 H = chr(height)
 13 
 14 out.write(GS)
 15 out.write(V)
 16 out.write(ZERO)
 17 out.write(NUL)
 18 
 19 out.write(H)
 20 out.write(NUL)
 21 out.write(W)
 22 out.write(NUL)
 23 
 24 for y in range(0, height):
 25     for x in range(0, width):
 26         out.write(chr(127))    # looks like `del` in ASCII mode
 27 
 28 out.close()

After about an hour or so of looking at binary data, I came to the following conclusion:

A *.TMB image is really just a serialized ESC/POS command to print a raster image.

Using the following command:

od -t a -v [YOUR_TMB_FILE] | head

we can view the binary data, as ASCII character data, in the beginning of the TMB file.

I had a file that looked something like this:

0000000  gs   v   0 nul   5 nul   P nul del del del del del del del del
0000020 del del del del del del del del del del del del del del del del
... snipped for brevity ...

According to the ESC/POS Programming Guide, the ASCII command to print a raster image is:

GS V 0

Hmm.. Interesting!

On a whim, I decided to convert 5 and P to their decimal equivalents, which are 53 and 80 respectively, the exact dimensions of my .TMB image (actually, its 80x53)!

Everything fell into place after this. The remainder of a .TMB file is just the binary image data.

Here is a one-off Python script I wrote to test my theory:

  1 out = open('test.TMB', 'wb')
  2 
  3 width = 80
  4 height = 53
  5 
  6 NUL = chr(0)
  7 GS = chr(29)
  8 V = chr(118)
  9 ZERO = chr(48)
 10 
 11 W = chr(width)
 12 H = chr(height)
 13 
 14 out.write(GS)
 15 out.write(V)
 16 out.write(ZERO)
 17 out.write(NUL)
 18 
 19 out.write(H)
 20 out.write(NUL)
 21 out.write(W)
 22 out.write(NUL)
 23 
 24 for y in range(0, height):
 25     for x in range(0, width):
 26         out.write(chr(127))    # looks like `del` in ASCII mode
 27 
 28 out.close()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文