python3库用于生成各种标识

customidenticon的Python项目详细描述


客户识别图标

image

用于生成各种标识图标的Python库

image

功能

  • 3种不同类型的标识
  • 更改最终图像大小(元素大小、元素数量)
  • 更改边框大小
  • 更改背景色
  • 更改元素的透明度
  • 更改输出格式(PNG、JPEG等)
  • 哈希算法的选择(包括您自己的)

安装

pip install customidenticon

用法

结束图像大小=大小*块大小+边框*2

importcustomidenticonidenticon=customidenticon.create("Test data",# Datatype="pixels",# Type of algorithm (pixels, blocks or layers)format="png",# Output formatsalt="",# salt for more variantsbackground="#f0f0f0",# background colorblock_visibility=140,# transparency of elements in the image (0-255)block_size=30,# size of elements (px)border=25,# border (px)size=5,# number of elementshash_func=None# hash function (auto))

保存

importcustomidenticonidenticon=customidenticon.create("Test data",size=5)# identicon = b"\x89PNG\r\n\x1a\n\x00\x00\x00..."# save to filewithopen("identicon.png","wb")asf:f.write(identicon)# to imageimportiofromPILimportImageimage=Image.open(io.BytesIO(identicon))

哈希算法

对更改算法使用hashlib

importhashlibimportcustomidenticonidenticon=customidenticon.create("Test data",hash_func=hashlib.sha3_256)

自定义哈希算法示例

importcustomidenticonclassMySuperHashAlgorithm:def__init__(self,*args):passdefhexdigest(self):return"0"*200identicon=customidenticon.create("Test data",hash_func=MySuperHashAlgorithm)

示例

importcustomidenticon# Create github-like (5x5)identicon1=customidenticon.create("Test")# 200x200px (default for all)# oridenticon1=customidenticon.create("Test",type="pixels")# Create "pixels" type (6x6)# End image size 200x200px (6 * 25 + 25 * 2)identicon2=customidenticon.create("Test",size=6,block_size=25)# Create "layers" type (3 layer)# End image size 200x200px (default size = 3 and block_size = 50)identicon4=customidenticon.create("Test",type="layers")# Create "layers" type (8 layer)# End image size 200x200px (8 * 20 + 20 * 2)identicon5=customidenticon.create("Test",type="layers",size=8,block_size=20,border=20)# Create "blocks" type (3x3) (200x200px)identicon6=customidenticon.create("Test",type="block",block_visibility=100)
结果

image

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java什么是OSGiDB访问的高级体系结构布局?   java如何使用控制台从文件夹中选择任何文件?   安卓对Java服务器的语言支持在过去3分钟内崩溃了5次。服务器将不会重新启动   捕获java异常不需要抛出,但IOException需要抛出   java在计时器运行一次后停止计时器   更新查询中的java双引号   java如何将一串数字、空格和逗号更改为整数数组列表   swing jTable paint()导致了java。lang.OutOfMemoryError:Java堆空间   java将其翻译成英语   java我可以重定向到另一个网页中的网页吗?   java如何在hibernate中将2个子类映射为1父抽象类?   将PDF页面导出到Java中的一系列图像   java使用hashmaps填充ArrayList   无法在Java上识别Java版本。通用域名格式   java想要使用可滚动的JTextArea,但它不起作用   java如何将字符串的值四舍五入到小数点后2位   java如何对点进行缩放?   从MongoDB Java文档的内部数组中获取值