A fractional width like `width=600.5` returns the full 1200x630 image
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 88/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript
调研方向
阅读 src/lib/api-validation.ts 中的 resolveDimensions 及其在 tests/api/og.test.ts 中的测试;issue 指出了小数宽度的处理路径和预期尺寸。在尺寸解析器和 API 路由中补充小数宽度的测试,然后确保列出的检查、测试和构建命令均通过。完成的标准是:小数宽度的响应符合验收标准,同时保留现有的整数宽度和小数高度行为。
由索引模型根据 Issue 内容生成。
描述
On dev, /api/og?width=600 returns a 600x315 PNG, but /api/og?width=600.5 returns 1200x630, and so does width=333.3. Run npm run dev and open http://localhost:4321/api/og?width=600.5 to see it.
The schema accepts any number from 200 to 2400 (src/lib/api-validation.ts, lines 16 to 19), and resolveDimensions (line 46) keeps the fraction. src/pages/api/og.ts passes the width to the renderer as scaleDown (line 82), which becomes resvg's fitTo width (src/lib/og-engine.ts, lines 88 to 91). resvg-wasm 2.6.2 ignores a fitTo width that isn't a whole number and renders the SVG at its own size, 1200x630. width=600.0 works because it parses to 600.
A fractional height on its own is fine, because the width derived from it is rounded (line 74): height=315.5 gives 601x316.
This came in with #142 (the fix for #85), which isn't released yet. Production still runs v1.6.0, where width crops the canvas instead of scaling it, and there width=600.5 gives a 601x630 image. The next release is planned for Friday, so it would be good to fix this before then.
What to do
- Round the width to a whole number at the start of
resolveDimensions. Thenwidth=600.5works likewidth=601and gives 601x316. The height doesn't need it: only the width goes to the renderer, and a width derived fromheightis already rounded. - Round instead of rejecting fractions with
.int(). Production acceptswidth=600.5today and returns an image, so a 400 would break URLs that work now.
Where to look
src/lib/api-validation.ts: thewidthandheightschema (lines 16 to 23) andresolveDimensions(lines 46 to 96)src/pages/api/og.ts:scaleDown(line 82)src/lib/og-engine.ts:fitTo(lines 88 to 91)tests/api/og.test.ts: theresolveDimensionstests (line 102) and the route tests for sizes (line 361)
Acceptance criteria
-
/api/og?width=600.5returns a 601x316 PNG, andwidth=333.3returns 333x175 -
height=315.5still returns 601x316, and whole numbers work as before - Tests for fractional widths in
resolveDimensionsand in the route -
npm run check,npm run testandnpm run buildpass
Want to work on this? Comment below and I'll assign it to you. Please take one issue at a time, branch off dev, and open your PR against dev with Closes #167 in the description.
- 主要语言
- TypeScript
- 星标
- 8
- 派生
- 4
- 平均合并
- 5 小时 44 分钟
- 30 天内合并 PR
- 83
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
codercops/ogcops 的其他 Issue
-
Add the Order Status e-commerce template (`ecommerce-order-status`)可能已有人在做 @piyusshhjangid 今天认领。 未关闭good first issue hacktoberfest templates
codercops/ogcops#181 · 4 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Add the Cheat Sheet tutorial template (`tutorial-cheat-sheet`)可能已有人在做 @srikar-naidu 今天认领。 未关闭hacktoberfest help wanted templates
难度 2/5 1-3 小时 新手友好度 45/100
codercops/ogcops#180 · 3 条评论 ·
维护者通常 1 天内回复
-
Add the Call for Speakers event template (`event-call-for-speakers`)可能已有人在做 @Saifjafri212213 今天认领。 未关闭good first issue hacktoberfest templates
codercops/ogcops#177 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Add the Day Streak developer template (`developer-day-streak`)可能已有人在做 @srikar-naidu 今天认领。 未关闭hacktoberfest help wanted templates
codercops/ogcops#176 · 3 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
hacktoberfest
难度 1/5 1 小时以内 新手友好度 35/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
db-ux-design-system/core-web#8613 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
bug internal-plugin pr-welcome upstream
难度 2/5 1-3 小时 新手友好度 78/100
dsh-tauri-desk/deepseek-harness-desktop#1225 · 1 条评论 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
unjs/unhead#1027 · 1 个 reaction ·
维护者通常 1 天内回复