Example code in ImageText documentation makes incorrect use of get_bbox()

未关闭
#10,583 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@mmporong 已经在做这个了。

开始于 2026年11月22日。

  • #10584 来自 @mmporong —— 未关闭

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
25/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
documentation

调研方向

The example is in the ImageText reference page, where text.get_bbox()[2:] is used to size the Image.new call. Open the linked pull request #10584 first, since a fix is already under way. Done means the example accounts for the bounding box's left and top offsets, so the image size and draw position are correct.

由索引模型根据 Issue 内容生成。

描述

Documentation

The documentation for ImageText uses the following code:

im = Image.new("RGB", text.get_bbox()[2:])
d = ImageDraw.Draw(im)
d.text((0, 0), text, "#f00")

It will create an image of the wrong size because it will not subtract the left and top values of the bounding box. Furthermore, it will make it impossible to adjust the position of im relative to a different anchor without, again, subtracting the left and top values of the default bbox.

主要语言
Python
星标
14k
派生
2.6k
平均合并
1 天 1 小时
30 天内合并 PR
205

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python-pillow/Pillow 的其他 Issue

查看 python-pillow/Pillow 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。