Skip to content

Commit

Permalink
feat: make avatar border configurable (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciNyan authored Mar 27, 2024
1 parent 2caab52 commit 632429a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions packages/pixel-profile-server/src/github-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ githubStats.get('/', async (c) => {
screen_effect,
show,
username,
theme
theme,
avatar_border
} = req.query()

res.headers.set('Content-Type', 'image/png')
Expand Down Expand Up @@ -51,7 +52,8 @@ githubStats.get('/', async (c) => {
includeAllCommits,
pixelateAvatar: parseBoolean(pixelate_avatar),
theme: parseString(theme),
screenEffect: parseBoolean(screen_effect)
screenEffect: parseBoolean(screen_effect),
avatarBorder: parseBoolean(avatar_border)
}

const result = await renderStats(stats, options)
Expand Down
12 changes: 8 additions & 4 deletions packages/pixel-profile/src/cards/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Options = {
hiddenStatsKeys?: string[]
includeAllCommits?: boolean
pixelateAvatar?: boolean
avatarBorder?: boolean
}

export async function renderStats(stats: Stats, options: Options = {}): Promise<Buffer> {
Expand All @@ -49,9 +50,12 @@ export async function renderStats(stats: Stats, options: Options = {}): Promise<
includeAllCommits = false,
pixelateAvatar = true,
screenEffect = false,
avatarBorder,
theme = ''
} = options

const applyAvatarBorder = avatarBorder !== undefined ? avatarBorder : theme !== ''

if (hiddenStatsKeys.includes('avatar')) {
modifiedAvatarUrl = ''
}
Expand All @@ -65,7 +69,7 @@ export async function renderStats(stats: Stats, options: Options = {}): Promise<

const [fontData, avatar] = await Promise.all([
readFile(fontPath),
makeAvatar(modifiedAvatarUrl, pixelateAvatar, !!theme)
makeAvatar(modifiedAvatarUrl, pixelateAvatar, applyAvatarBorder)
])

const _stats = {
Expand Down Expand Up @@ -151,7 +155,7 @@ export async function renderStats(stats: Stats, options: Options = {}): Promise<

const BASE_AVATAR_BLOCK_SIZE = 6.82

async function makeAvatar(url: string, pixelateAvatar: boolean, enableFrame: boolean): Promise<string> {
async function makeAvatar(url: string, pixelateAvatar: boolean, applyAvatarBorder: boolean): Promise<string> {
if (!url) {
return ''
}
Expand All @@ -163,12 +167,12 @@ async function makeAvatar(url: string, pixelateAvatar: boolean, enableFrame: boo
if (pixelateAvatar) {
const blockSize = (height / AVATAR_SIZE.AVATAR_HEIGHT) * BASE_AVATAR_BLOCK_SIZE
pixels = pixelate(pixels, width, height, blockSize)
if (enableFrame) {
if (applyAvatarBorder) {
pixels = addBorder(pixels, width, height, {
frameWidthRatio: 0.025
})
}
} else {
} else if (applyAvatarBorder) {
pixels = addBorder(pixels, width, height, { frameWidthRatio: 0.0167, enabledCornerRemoval: false })
}

Expand Down
2 changes: 1 addition & 1 deletion packages/pixel-profile/src/theme/images/fuji.ts

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 632429a

Please sign in to comment.