生成github贡献者前14头像组

简介: 生成github贡献者前14头像组


摆脱心事的最好方法是工作。——车尔尼雪夫斯基

这里当然完全用python也能行,我这里快速弄出来

先在chrome里打开检查,然后选中

chrome控制台console里执行

Array.from($0.querySelectorAll(".avatar")).map(({src})=>src)

得到

[
    "https://avatars.githubusercontent.com/u/28334419?s=64&v=4",
    "https://avatars.githubusercontent.com/u/1481125?s=64&v=4",
    "https://avatars.githubusercontent.com/u/15142701?s=64&v=4",
    "https://avatars.githubusercontent.com/u/20453060?s=64&v=4",
    "https://avatars.githubusercontent.com/in/2141?s=64&v=4",
    "https://avatars.githubusercontent.com/u/12861772?s=64&v=4",
    "https://avatars.githubusercontent.com/in/29110?s=64&v=4",
    "https://avatars.githubusercontent.com/u/16700837?s=64&v=4",
    "https://avatars.githubusercontent.com/u/39977647?s=64&v=4",
    "https://avatars.githubusercontent.com/u/52746628?s=64&v=4",
    "https://avatars.githubusercontent.com/u/5666807?s=64&v=4",
    "https://avatars.githubusercontent.com/u/9296576?s=64&v=4",
    "https://avatars.githubusercontent.com/u/41781780?s=64&v=4",
    "https://avatars.githubusercontent.com/u/3936684?s=64&v=4"
]

然后新建个java临时文件下载

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
class Scratch {
    public static void main(String[] args) {
        String[] imageUrls = {
                "https://avatars.githubusercontent.com/u/28334419?s=64&v=4",
                "https://avatars.githubusercontent.com/u/1481125?s=64&v=4",
                "https://avatars.githubusercontent.com/u/15142701?s=64&v=4",
                "https://avatars.githubusercontent.com/u/20453060?s=64&v=4",
                "https://avatars.githubusercontent.com/in/2141?s=64&v=4",
                "https://avatars.githubusercontent.com/u/12861772?s=64&v=4",
                "https://avatars.githubusercontent.com/in/29110?s=64&v=4",
                "https://avatars.githubusercontent.com/u/16700837?s=64&v=4",
                "https://avatars.githubusercontent.com/u/39977647?s=64&v=4",
                "https://avatars.githubusercontent.com/u/52746628?s=64&v=4",
                "https://avatars.githubusercontent.com/u/5666807?s=64&v=4",
                "https://avatars.githubusercontent.com/u/9296576?s=64&v=4",
                "https://avatars.githubusercontent.com/u/41781780?s=64&v=4",
                "https://avatars.githubusercontent.com/u/3936684?s=64&v=4"
        };
        for (int i = 0; i < imageUrls.length; i++) {
            String savePath = "image_" + (i + 1) + ".jpg"; // Or use another method to determine filenames
            try {
                downloadImage(imageUrls[i], savePath);
                System.out.println("Downloaded: " + savePath);
            } catch (IOException e) {
                System.err.println("Error downloading " + imageUrls[i] + ": " + e.getMessage());
            }
        }
    }
    public static void downloadImage(String imageUrl, String savePath) throws IOException {
        URL url = new URL(imageUrl);
        try (BufferedInputStream in = new BufferedInputStream(url.openStream());
             FileOutputStream fileOutputStream = new FileOutputStream(savePath)) {
            byte dataBuffer[] = new byte[1024];
            int bytesRead;
            while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
                fileOutputStream.write(dataBuffer, 0, bytesRead);
            }
        } catch (IOException e) {
            // Handle exception
            throw e;
        }
    }
}

然后是用python将图片转成圆角,然后合成图片

GithubIireAchao:Downloads achao$ touch create_collage.py

创建文件

from PIL import Image, ImageDraw
import os
def create_rounded_image(image_path, output_path, corner_radius=50, final_size=(64, 64)):
    """Create a rounded corner image, resize it to 64x64, and save it."""
    try:
        img = Image.open(image_path)
        # Resize with antialiasing (using LANCZOS resampling)
        img = img.resize(final_size, Image.Resampling.LANCZOS).convert("RGBA")
        # Create rounded mask
        mask = Image.new('L', img.size, 0)
        draw = ImageDraw.Draw(mask)
        draw.rounded_rectangle([(0, 0), img.size], corner_radius, fill=255)
        # Apply rounded mask to image
        img.putalpha(mask)
        # Save with rounded corners
        img.save(output_path)
        print(f"Processed and saved: {os.path.basename(output_path)}")
    except Exception as e:
        print(f"Error processing {os.path.basename(image_path)}: {e}")
def create_collage(image_paths, output_path, images_per_row=7, spacing=10):
    """Create a collage of images with transparent background."""
    try:
        images = [Image.open(path).convert("RGBA") for path in image_paths]
        image_width, image_height = images[0].size
        total_width = image_width * images_per_row + spacing * (images_per_row - 1)
        total_rows = (len(images) + images_per_row - 1) // images_per_row
        total_height = image_height * total_rows + spacing * (total_rows - 1)
        # Collage with transparent background
        collage = Image.new('RGBA', (total_width, total_height), (0, 0, 0, 0))
        for index, image in enumerate(images):
            row_num = index // images_per_row
            col_num = index % images_per_row
            x = col_num * (image_width + spacing)
            y = row_num * (image_height + spacing)
            collage.paste(image, (x, y), image)
        collage.save(output_path)
        print("Collage created successfully.")
    except Exception as e:
        print(f"Error creating collage: {e}")
# Paths and settings
image_folder = "/Users/achao/Downloads"
output_folder = image_folder
rounded_images = []
for i in range(1, 15):
    input_path = os.path.join(image_folder, f"image_{i}.jpg")
    output_path = os.path.join(output_folder, f"rounded_{i}.png")
    create_rounded_image(input_path, output_path, corner_radius=50, final_size=(64, 64))
    rounded_images.append(output_path)
collage_output_path = os.path.join(output_folder, "collage.png")
create_collage(rounded_images, collage_output_path)

这里需要下载PIL

GithubIireAchao:Downloads achao$ python3 create_collage.py
Traceback (most recent call last):
  File "/Users/achao/Downloads/create_collage.py", line 1, in <module>
    from PIL import Image, ImageOps
ModuleNotFoundError: No module named 'PIL'
GithubIireAchao:Downloads achao$ pip3 install Pillow
Looking in indexes: https://pypi.org/simple, https://packagecloud.io/github/git-lfs/pypi/simple
Collecting Pillow
  Downloading pillow-10.3.0-cp310-cp310-macosx_11_0_arm64.whl.metadata (9.2 kB)
Downloading pillow-10.3.0-cp310-cp310-macosx_11_0_arm64.whl (3.4 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.4/3.4 MB 60.2 kB/s eta 0:00:00
Installing collected packages: Pillow
Successfully installed Pillow-10.3.0

最后:

GithubIireAchao:Downloads achao$ python3 create_collage.py
Processed and saved: rounded_1.png
Processed and saved: rounded_2.png
Processed and saved: rounded_3.png
Processed and saved: rounded_4.png
Processed and saved: rounded_5.png
Processed and saved: rounded_6.png
Processed and saved: rounded_7.png
Processed and saved: rounded_8.png
Processed and saved: rounded_9.png
Processed and saved: rounded_10.png
Processed and saved: rounded_11.png
Processed and saved: rounded_12.png
Processed and saved: rounded_13.png
Processed and saved: rounded_14.png
Collage created successfully.
GithubIireAchao:Downloads achao$

成图:


相关文章
|
4月前
|
开发工具 git 开发者
2024最简七步完成 将本地项目提交到github仓库方法
该文章提供了一个简洁的七步教程,指导用户如何将本地项目提交到GitHub仓库。
2024最简七步完成 将本地项目提交到github仓库方法
|
2月前
|
编解码 Oracle Java
java9到java17的新特性学习--github新项目
本文宣布了一个名为"JavaLearnNote"的新GitHub项目,该项目旨在帮助Java开发者深入理解和掌握从Java 9到Java 17的每个版本的关键新特性,并通过实战演示、社区支持和持续更新来促进学习。
91 3
|
4月前
|
存储 安全 Java
【事故】记一次意外把公司项目放到GitHub并被fork,如何使用DMCA下架政策保障隐私
在一次意外中,作者因三年前将测试代码遗忘在GitHub上而遭遇了代码被他人fork的问题。为解决这一危机,作者详细介绍了如何通过GitHub的DMCA下架通知流程安全删除敏感代码,包括处理私人信息和商标侵权的具体步骤。本文不仅提供了实用的操作指南,还强调了及时响应的重要性,帮助读者避免类似风险
70 1
【事故】记一次意外把公司项目放到GitHub并被fork,如何使用DMCA下架政策保障隐私
|
4月前
|
数据采集 编解码 算法
Github | 推荐一个Python脚本集合项目
Github | 推荐一个Python脚本集合项目
|
4月前
|
Rust 前端开发 JavaScript
Github 2024-05-20 开源项目周报 Top15
根据Github Trendings的统计,2024年5月20日当周共有15个项目上榜。按开发语言分类,项目数量如下:Python项目5个,TypeScript项目3个,C++项目2个,Jupyter Notebook项目2个,C、Go、Rust和C#项目各1个。介绍了多个值得关注的项目,包括ChatGPT桌面应用程序、Fooocus图像生成软件、Jellyfin媒体系统等。这些项目涵盖了多种功能和技术领域,值得关注和研究。
76 3
|
4月前
|
SQL JavaScript 前端开发
Github 2024-08-05 开源项目周报 Top15
根据 Github Trendings 的统计,本周(2024年8月5日统计)共有15个项目上榜。以下是根据开发语言汇总的项目数量: - Go 项目:4个 - JavaScript 项目:3个 - Python 项目:3个 - Java 项目:2个 - TypeScript 项目:2个 - C 项目:1个 - Shell 项目:1个 - Dockerfile 项目:1个 - 非开发语言项目:1个
151 2
|
4月前
|
人工智能 Rust JavaScript
Github 2024-08-26 开源项目周报Top15
根据Github Trendings的统计,本周共有15个项目上榜。以下是按开发语言汇总的项目数量:Python项目8个,TypeScript、C++ 和 Rust 项目各2个,Jupyter Notebook、Shell、Swift 和 Dart 项目各1个。其中,RustDesk 是一款用 Rust 编写的开源远程桌面软件,可作为 TeamViewer 的替代品;Whisper 是一个通用的语音识别模型,基于大规模音频数据集训练而成;初学者的生成式人工智能(第2版)则是由微软提供的18门课程,教授构建生成式AI应用所需的知识。
147 1
|
4月前
|
Rust Dart 前端开发
Github 2024-08-19 开源项目周报Top15
根据Github Trendings的统计,本周(2024年8月19日统计)共有15个项目上榜。按开发语言分类,上榜项目数量如下:Python项目最多,有7项;其次是JavaScript和TypeScript,各有3项;Dart有2项;HTML、PowerShell、Clojure和C++各1项。此外,还介绍了多个热门项目,包括Bootstrap 5、RustDesk、ComfyUI、易采集、Penpot等,涵盖了Web开发、远程桌面、自动化测试、设计工具等多个领域。
123 1