使用python identicon库创建类似Github上用的头像
来源:互联网 发布:产品优化方案模板 编辑:程序博客网 时间:2024/06/07 02:00
Identicon在很多大型IT网站上可以见到,比如Github,Sourceforge,Stackoveflow等等, 刚刚注册的账号的个人信息的默认图标都是一些看上去像七巧板拼凑的图案,对称又变化多端。
本人也是因为好奇才在网上搜了这个算法,主要是哈希算法,把邮箱或者IP的信息图形化,很直观。
这个算法有很多版本, php的, .net的, python的, ruby的, 因为咱们社区是python的, 所以这里给大家发一个python版本的.
使用示例:
- 直接到 https://github.com/shnjp/identicon 下载identicon.py,
- 将identicon.py放到你能找到的地方.
- 然后在相同的目录里新建一个test.py
- 打开test.py
输入以下代码:
import identiconimg= identicon.render_identicon('123123', 16)img.show()
这样就能够看到图像了, 大小是3*16=48. 即图片大小是48X48像素的尺寸.如果报错了, 就是你没有安装python的图像处理模块PIL, 安装之后再试.
保存图像
上面的代码只是简单的使用, 还没保存.保存代码如下:
import identiconimg= identicon.render_identicon('123123', 16)img.save('123123.png')
会在相同的目录保存一个png格式的图片
批量生成图片
代码如下:
import identicondef gen_identicon(code,size): img= identicon.render_identicon(code, 16) #img.show() img.save('%s_%s.png'%(code,size))for x in xrange(10000000,10000000+5): gen_identicon(x, 16)for x in xrange(20000000,20000000+5): gen_identicon(x, 16)for x in xrange(40000000,40000000+5): gen_identicon(x, 16)for x in xrange(80000000,80000000+5): gen_identicon(x, 16)for x in xrange(160000000,160000000+5): gen_identicon(x, 16)
说明:
identicon.render_identicon(code, 16)
这里的code是一个数值, 或者字符串数值, 如果code比较大, 比如code=10000000, 生成的图片就是彩色的. code比较小, 比如code=1~100之间的, 生成的图片就是黑白色的.
完.
0 0
- 使用python identicon库创建类似Github上用的头像
- 哈希头像生成器Identicon
- 如何修改github上的头像
- GitHub的使用(上)—— 创建和更新
- 使用hexo和Github上创建自己的博客
- 用pictureBox做类似QQ头像的功能
- Github使用一:创建项目并上传到Github上
- 类似github的框架
- 如何删除github上已创建的代码库
- GitHub的使用(上)
- 工作上github的使用
- github上创建静态的blog资源
- 完美实现类似QQ的自拍头像、上传头像功能!
- Github:在Github上创建自己的代码仓库
- Github:在Github上创建自己的代码仓库
- 使用ECharts 实现类似github的Punch Card 图
- 类似微信未读消息的头像标记
- github上创建资源库
- CentOS 7 安装Broadcom无线网卡
- 4、contiki系统开发-UDP-IPV6数据传输功能测试
- Android学习笔记之二十 BroadcastReceiver
- JAVA------集合
- Ural 1303 Minimal Coverage(贪心)
- 使用python identicon库创建类似Github上用的头像
- 2014-10-25Android学习------布局处理(三)------常见且常用的列表布局
- 使用ID号来删除特定文档
- [IOS]iOS8下的UIAlertContoller初探
- 利用eclipse开发动态web项目
- 一天一个 linux 基础知识(1)
- 幸福了吗?——第一次阅读笔记
- ubuntu 12.10 常见问题及解决方法(收集汇总)
- 从今儿开始,踏踏实实的写博客