github默认头像 avatar
生成独一无二的头像https://github.com/identicons/chucklu.png 将最后的图片的名字修改之后,会自动生成新的
Identicons! | The GitHub Blog
GitHub is about to get a lot more colorful. Starting today, we are generating Identicons for anyone without a Gravatar:
Our Identicons are simple 5×5 “pixel” sprites that are generated using a hash of the user’s ID. The algorithm walks through the hash and turns pixels on or off depending on even or odd values. These generated patterns, combined with hash-determined color values, ensures a huge number of unique Identicons.
Using a Gravatar but want to see what your identicon would be? Use this URL and replace my GitHub login with yours:
https://identicons.github.com/jasonlong.png
How does github generate github.com/identicons
GitHub generates Identicons using a specific algorithm that takes the user's username or email address as input and generates a unique image as output.
The algorithm works by hashing the input using the MD5 cryptographic hash function to produce a 128-bit hash value. This hash value is then used to generate a 5x5 grid of colored squares, with each square being either white or one of a few specific colors. The position of each square in the grid is determined by the value of one of the bytes in the hash value, and the color of each square is determined by the value of the corresponding byte in the hash value.
The resulting image is a unique and colorful abstract pattern that serves as a visual representation of the user's identity. Because the images are generated based on a hash of the user's username or email address, they are consistent and reproducible, which means that the same user will always be associated with the same Identicon.
Implement the avatar generation for github.com/identicons in Python with PIL
Sure, here is a Python code snippet that generates a Github-like identicon using the Python Imaging Library (PIL):
from PIL import Image
# Define the input string and hash it using SHA1
input_string = "hello"
hash_value = hashlib.sha1(input_string.encode('utf-8')).hexdigest()
# Extract the first 15 characters of the hash
short_hash = hash_value[:15]
# Initialize the size of the image and the size of each square
image_size = 420
square_size = image_size // 7
# Initialize the image and fill it with a light gray color
image = Image.new('RGB', (image_size, image_size), (240, 240, 240))
# Define the color for the foreground squares based on the hash value
color = (
int(short_hash[0:2], 16),
int(short_hash[2:4], 16),
int(short_hash[4:6], 16)
)
# Loop through the hash and draw the squares
for i, char in enumerate(short_hash):
# Calculate the position of the square
x = (i % 5) * square_size
y = (i // 5) * square_size
# If the character is odd, draw the square
if int(char, 16) % 2 == 1:
draw = ImageDraw.Draw(image)
draw.rectangle((x, y, x + square_size, y + square_size), fill=color)
# Show the image
image.show()
This code generates an identicon using the string "hello". It first hashes the string using SHA1 and extracts the first 15 characters of the hash. It then initializes an image with a light gray color and loops through the hash, drawing squares based on the value of each character. If the character is odd, a square is drawn with a color based on the hash value. Finally, the image is displayed using the show()
method.
Mathematica实战范例:[15]Github 头像制作_电脑软件-百度经验 (baidu.com)
How is the default user avatar generated? - Meta Stack Exchange
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2021-05-27 Why is this NuGet dependency missing when compiling .NET Framework project depending on .NET Standard?
2020-05-27 Subquery using Exists 1 or Exists *
2020-05-27 NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL: SQL Server
2019-05-27 get the deadlock information from sql server
2019-05-27 IIS的站点配置存储在applicationHost.config
2019-05-27 three dots in git
2017-05-27 让用户只能看到自己有权限的数据库