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

Đang mở
#10,583 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@mmporong đang làm issue này rồi.

Từ ngày 22/11/2026.

  • #10584 của @mmporong — đang mở

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
25/100
Loại issue
Tài liệu
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
documentation

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
14k
Fork
2.6k
Merge trung bình
1 ngày 1 giờ
Pull request đã merge (30 ngày)
205

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python-pillow/Pillow

Tất cả issue của python-pillow/Pillow

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.