You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

doc.go 1.5KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2015 by caixw, All rights reserved.
  2. // Use of this source code is governed by a MIT
  3. // license that can be found in the LICENSE file.
  4. // 一个基于hash值生成随机图像的包。
  5. //
  6. // 关于identicon并没有统一的标准,一般用于在用户注册时,
  7. // 取用户的邮箱或是访问IP等数据(也可以是其它任何数据),
  8. // 进行hash运算,之后根据hash数据,产生一张图像,
  9. // 这样即可以为用户产生一张独特的头像,又不会泄漏用户的隐藏。
  10. //
  11. // 在identicon中,把图像分成以下九个部分:
  12. // -------------
  13. // | 1 | 2 | 3 |
  14. // -------------
  15. // | 4 | 5 | 6 |
  16. // -------------
  17. // | 7 | 8 | 9 |
  18. // -------------
  19. // 其中1、3、9、7为不同角度(依次增加90度)的同一张图片,
  20. // 2、6、8、4也是如此,这样可以保持图像是对称的,比较美观。
  21. // 5则单独使用一张图片。
  22. //
  23. // // 根据用户访问的IP,为其生成一张头像
  24. // img, _ := identicon.Make(128, color.NRGBA{},color.NRGBA{}, []byte("192.168.1.1"))
  25. // fi, _ := os.Create("/tmp/u1.png")
  26. // png.Encode(fi, img)
  27. // fi.Close()
  28. //
  29. // // 或者
  30. // ii, _ := identicon.New(128, color.NRGBA{}, color.NRGBA{}, color.NRGBA{})
  31. // img := ii.Make([]byte("192.168.1.1"))
  32. // img = ii.Make([]byte("192.168.1.2"))
  33. //
  34. // NOTE: go test 会在当前目录的testdata文件夹下产生大量的随机图片。
  35. // 要运行测试,必须保证该文件夹是存在的,且有相应的写入权限。
  36. package identicon