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

Offen
#10,583 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@mmporong arbeitet bereits daran.

Seit 22.11.2026.

  • #10584 von @mmporong — offen

Bewertung

Schwierigkeit
1/5
Geschätzter Aufwand
Unter einer Stunde
Anfängerfreundlichkeit
25/100
Issue-Typ
Dokumentation
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
documentation

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
14k
Forks
2.6k
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
205

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python-pillow/Pillow

Alle Issues in python-pillow/Pillow

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.