Skip to content

Commit 2ca15df

Browse files
lgc2333codexantfubot
authored
fix!: use render-local crop ids (#122)
Co-authored-by: Codex <codex@openai.com> Co-authored-by: Anthony Fu (via agent) <reg-github-bot@antfu.me>
1 parent e5f4e89 commit 2ca15df

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/processing/svg.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { BadgePreset, ImageFormat, Sponsor, SponsorkitRenderOptions, Sponsorship } from '../types.ts'
2-
import crypto from 'node:crypto'
32
import { resizeImage } from './image.ts'
43

54
export function genSvgImage(
@@ -9,8 +8,8 @@ export function genSvgImage(
98
radius: number,
109
base64Image: string,
1110
imageFormat: ImageFormat,
11+
cropId: string,
1212
) {
13-
const cropId = `c${crypto.createHash('md5').update(base64Image).digest('hex').slice(0, 6)}`
1413
return `
1514
<clipPath id="${cropId}">
1615
<rect x="${x}" y="${y}" width="${size}" height="${size}" rx="${size * radius}" ry="${size * radius}" />
@@ -25,6 +24,7 @@ export async function generateBadge(
2524
preset: BadgePreset,
2625
radius: number,
2726
imageFormat: ImageFormat,
27+
cropId: string,
2828
) {
2929
const { login } = sponsor
3030
let name = (sponsor.name || sponsor.login).trim()
@@ -55,20 +55,25 @@ export async function generateBadge(
5555
${preset.name
5656
? `<text x="${x + size / 2}" y="${y + size + 18}" text-anchor="middle" class="${preset.name.classes || 'sponsorkit-name'}" fill="${preset.name.color || 'currentColor'}">${encodeHtmlEntities(name)}</text>
5757
`
58-
: ''}${genSvgImage(x, y, size, radius, avatarBase64, imageFormat)}
58+
: ''}${genSvgImage(x, y, size, radius, avatarBase64, imageFormat, cropId)}
5959
</a>`.trim()
6060
}
6161

6262
export class SvgComposer {
6363
height = 0
6464
body = ''
65+
private cropId = 0
6566

6667
readonly config: Required<SponsorkitRenderOptions>
6768

6869
constructor(config: Required<SponsorkitRenderOptions>) {
6970
this.config = config
7071
}
7172

73+
getNextCropId() {
74+
return `c${this.cropId++}`
75+
}
76+
7277
addSpan(height = 0) {
7378
this.height += height
7479
return this
@@ -96,7 +101,8 @@ export class SvgComposer {
96101
const x = offsetX + preset.boxWidth * i
97102
const y = this.height
98103
const radius = s.sponsor.type === 'Organization' ? 0.1 : 0.5
99-
return await generateBadge(x, y, s.sponsor, preset, radius, this.config.imageFormat)
104+
const cropId = this.getNextCropId()
105+
return await generateBadge(x, y, s.sponsor, preset, radius, this.config.imageFormat, cropId)
100106
}))
101107

102108
this.body += sponsorLine.join('\n')

src/renders/circles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const circlesRenderer: SponsorkitRenderer = {
4848
},
4949
0.5,
5050
config.imageFormat,
51+
composer.getNextCropId(),
5152
))
5253
}
5354

0 commit comments

Comments
 (0)