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

Aperta
#10,583 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@mmporong ci sta già lavorando.

Dal 22/11/2026.

  • #10584 di @mmporong — aperta

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
25/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
documentation

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
14k
Fork
2.6k
Merge medio
1g 1h
PR unite (30g)
205

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python-pillow/Pillow

Tutte le issue di python-pillow/Pillow

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.