概述
这是一个python包。
优势
- 给出标签Identicon,可以单个/批量标识序列。对于某些只差一两个字符的序列,识别更方便。
- 可以生成pdf文件
劣势
- 只能生成标签,不提供解码。但是可以对照pdf确认序列与图像的对应关系。
- 生成pdf的包是该机构自己写的,需要调整代码以调整pdf的内容排布。
代码分析(简单)
位置:
sequenticon-master\sequenticon\sequenticon.py
# 函数
sequenticon(sequence, output_format='png', size=60, output_path=None)
'''
out_format:
One of "png", "base64", "html_image". If "png", raw PNG image data is
returned (as bytes). If base64, the png data is base64-encoded (string),
and if html_image, the returned string is ``<img src='data:X'/>`` where
X is base64 image data (this string is ready to be used in a webpage).
'''
sequenticon_batch(sequences, output_format='png', size=60, output_path=None)
sequenticon_batch_pdf(sequences, target=None, title="Sequenticons batch")
处理过程
- 获取序列
- 使用pydenticon包产生base64数据和图像
generator = pydenticon.Generator(SETTINGS["rows"], SETTINGS["columns"],
foreground=SETTINGS["color_palette"])
img = generator.generate(sequence, size, size)
base_64 = base64.b64encode(img).decode()
数据转换&加密部分
实际是md5加密产生hash码,然后按照一定规则转为01矩阵,然后染色。查看:
你的路径\Lib\site-packages\pydenticon
你的路径\Lib\hashlib.py
如果找不到某些包的位置,可以在交互环境下先import 包名,然后直接输入包名,就会提示路径。(如果安装的时候失败了,会报错)
- 写出到图片/html/pdf
写出到pdf看pdf_reports包。这个包仍然是该公司的,使用的是weasyprint包,这个包能将html转为pdf。
win10下安装weasyprint包可能报错
ImportError: [PDF Reports] ERROR: The Weasyprint library did not loadproperly! You will not be able to generate PDF reports untilyou fix this issue.
Maybe you haven't installed the Cairo dependency?
In any other case the weasyprint docs may be able to help:
http://weasyprint.readthedocs.io/en/stable/install.html#windows
The original import error was no library called "cairo" was found
no library called "libcairo-2" was found
cannot load library 'libcairo.so': error 0x7e
cannot load library 'libcairo.2.dylib': error 0x7e
cannot load library 'libcairo-2.dll': error 0x7e
解决方案
其实是缺少GTK的包,这里我下载了
https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer
(国内速度慢的话使用工具)
安装完毕后重启电脑可以生效。