X Tutup
Skip to content

Commit fa1fb4e

Browse files
authored
Merge pull request #8466 from skyash-dev/feat/readme-contributors-png
feat: generate contributors PNG for README
2 parents 61464fb + f433241 commit fa1fb4e

File tree

5 files changed

+107
-4
lines changed

5 files changed

+107
-4
lines changed

.all-contributorsrc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,8 +1456,8 @@
14561456
{
14571457
"login": "FreddieRa",
14581458
"name": "Freddie Rawlins",
1459-
"avatar_url": "https://discourse-cdn-sjc2.com/standard10/user_avatar/discourse.processing.org/freddiera/120/4078_2.png",
1460-
"profile": "https://freddierawlins.wixsite.com/site",
1459+
"avatar_url": "https://avatars.githubusercontent.com/u/14854492?v=4",
1460+
"profile": "https://github.com/FreddieRa",
14611461
"contributions": [
14621462
"code",
14631463
"doc"
@@ -1466,7 +1466,7 @@
14661466
{
14671467
"login": "Luke_",
14681468
"name": "Luc de wit",
1469-
"avatar_url": "https://media.discordapp.net/attachments/499488127245615135/499488260435869696/normal_luke.png",
1469+
"avatar_url": "https://avatars.githubusercontent.com/u/37410843?v=4",
14701470
"profile": "https://github.com/justlucdewit",
14711471
"contributions": [
14721472
"code",
@@ -1860,7 +1860,7 @@
18601860
{
18611861
"login": "shaharyar-shamshi",
18621862
"name": "shaharyarshamshi",
1863-
"avatar_url": "https://avatars3.githubusercontent.com/u/17377195?v=4",
1863+
"avatar_url": "https://avatars.githubusercontent.com/u/17377195?v=4",
18641864
"profile": "https://github.com/shaharyar-shamshi",
18651865
"contributions": [
18661866
"translation"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Generate Contributors PNG
2+
3+
on:
4+
push:
5+
paths:
6+
- '.all-contributorsrc'
7+
8+
jobs:
9+
build:
10+
if: github.ref == 'refs/heads/main' && github.repository == 'processing/p5.js'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Setup Node
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: 20
19+
20+
- name: Install dependencies
21+
run: npm install canvas
22+
23+
- name: Run contributors-png generator
24+
run: node utils/contributors-png.js
25+
26+
- name: Reset all changes except contributors.png
27+
run: |
28+
git restore --staged .
29+
git add contributors.png
30+
git checkout -- .
31+
32+
- name: Create Pull Request
33+
uses: peter-evans/create-pull-request@v7
34+
with:
35+
commit-message: "Update contributors.png from .all-contributorsrc"
36+
branch: update-contributors-png
37+
title: "chore: update contributors.png from .all-contributorsrc"
38+
body: "This PR updates the contributors.png to reflect changes in .all-contributorsrc"
39+
add-paths: contributors.png
40+
token: ${{ secrets.ACCESS_TOKEN }}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,6 @@ Lead/Mentor Alumni
122122

123123
We recognize all types of contributions. This project follows the [all-contributors specification](https://github.com/all-contributors/all-contributors) and the [Emoji Key](https://github.com/all-contributors/all-contributors/blob/master/docs/emoji-key.md) ✨ for contribution types. Instructions to add yourself or add contribution emojis to your name are [here](https://github.com/processing/p5.js/issues/2309). You can also post an issue or comment on a pull request with the text: `@all-contributors please add @YOUR-USERNAME for THINGS` (where `THINGS` is a comma-separated list of entries from the [list of possible contribution types](https://github.com/all-contributors/all-contributors/blob/master/docs/emoji-key.md)) and our nice bot will add you to [CONTRIBUTORS.md](./CONTRIBUTORS.md) automatically!
124124

125+
![Grid of avatars representing contributors to the p5.js project](contributors.png)
126+
125127
Thanks to all the wonderful contributors! 💓

contributors.png

3.31 MB
Loading

utils/contributors-png.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const { createCanvas, loadImage } = require('canvas');
2+
const fs = require('fs');
3+
4+
const data = fs.readFileSync('.all-contributorsrc', 'utf-8');
5+
const parsed = JSON.parse(data);
6+
const contributors = parsed.contributors;
7+
8+
const AVATAR_SIZE = 50;
9+
const GAP = 4;
10+
const COLS = 40;
11+
const ROWS = Math.ceil(contributors.length / COLS);
12+
13+
const width = COLS * AVATAR_SIZE + (COLS - 1) * GAP;
14+
const height = ROWS * AVATAR_SIZE + (ROWS - 1) * GAP;
15+
16+
const canvas = createCanvas(width, height);
17+
const ctx = canvas.getContext('2d');
18+
19+
async function loadAvatar(url) {
20+
try {
21+
const res = await fetch(url);
22+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
23+
24+
const buffer = Buffer.from(await res.arrayBuffer());
25+
return await loadImage(buffer);
26+
} catch (err) {
27+
return null;
28+
}
29+
}
30+
31+
(async () => {
32+
for (let i = 0; i < contributors.length; i++) {
33+
const c = contributors[i];
34+
35+
const col = i % COLS;
36+
const row = Math.floor(i / COLS);
37+
38+
const x = col * (AVATAR_SIZE + GAP);
39+
const y = row * (AVATAR_SIZE + GAP);
40+
41+
const img = await loadAvatar(c.avatar_url);
42+
43+
ctx.save();
44+
ctx.beginPath();
45+
ctx.arc(
46+
x + AVATAR_SIZE / 2,
47+
y + AVATAR_SIZE / 2,
48+
AVATAR_SIZE / 2,
49+
0,
50+
Math.PI * 2
51+
);
52+
ctx.clip();
53+
54+
if (img) {
55+
ctx.drawImage(img, x, y, AVATAR_SIZE, AVATAR_SIZE);
56+
}
57+
ctx.restore();
58+
}
59+
60+
fs.writeFileSync('contributors.png', canvas.toBuffer('image/png'));
61+
})();

0 commit comments

Comments
 (0)
X Tutup