ejeschke / ginga

The Ginga astronomical FITS file viewer
BSD 3-Clause "New" or "Revised" License
120 stars 77 forks source link

Ginga incompatible with Pillow 10.0.0 #1061

Closed JuanCab closed 11 months ago

JuanCab commented 11 months ago

Ginga currently relies on a textsize attribute in Pillow that is now deprecated in Pillow 10.0.0. Temporary solution is to go back to Pillow 9.5.0, but this should probably addressed.

Specifically: while running ginga I get a chain of errors that comes down to:

Error redrawing image: 'ImageDraw' object has no attribute 'textsize'
Traceback (most recent call last):
  File "/Users/ZZZ/miniconda3/envs/stellardev/lib/python3.11/site-packages/ginga/ImageView.py", line 1368, in redraw_now
    self.redraw_data(whence=whence)
  File "/Users/ZZZ/miniconda3/envs/stellardev/lib/python3.11/site-packages/ginga/ImageView.py", line 1407, in redraw_data
    self.private_canvas.draw(self)
  File "/Users/ZZZ/miniconda3/envs/stellardev/lib/python3.11/site-packages/ginga/canvas/DrawingMixin.py", line 708, in draw
    super(DrawingMixin, self).draw(viewer)
  File "/Users/ZZZ/miniconda3/envs/stellardev/lib/python3.11/site-packages/ginga/canvas/CompoundMixin.py", line 126, in draw
    obj.draw(viewer)
  File "/Users/ZZZ/miniconda3/envs/stellardev/lib/python3.11/site-packages/ginga/canvas/types/basic.py", line 162, in draw
    cr.draw_text(cx, cy, self.text, rot_deg=self.rot_deg)
  File "/Users/ZZZ/miniconda3/envs/stellardev/lib/python3.11/site-packages/ginga/pilw/CanvasRenderPil.py", line 121, in draw_text
    wd, ht = self.cr.text_extents(text, self.font)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ZZZ/miniconda3/envs/stellardev/lib/python3.11/site-packages/ginga/pilw/PilHelp.py", line 134, in text_extents
    retval = self.ctx.textsize(text, font.font)
             ^^^^^^^^^^^^^^^^^
AttributeError: 'ImageDraw' object has no attribute 'textsize'

Turns out according to this documentation for Pillow 10.0.0 that textsize has been deprecated. It has been replaced with textlength. I did a quick experiment and replaced textsize with textlength in the calls in pilw/PilHelp.py but that doesn't fix it, apparently what is returned is changed as well. Did not have time to further investigate.

pllim commented 11 months ago

Is this a duplicate of #1057 and has been fixed in https://github.com/ejeschke/ginga/pull/1058 ?

JuanCab commented 11 months ago

Yeah, it appears to be a duplicate. Sorry, I searched for the wrong term before posting.

ejeschke commented 11 months ago

@JuanCab, tip: if you are using in a notebook, install pycairo to get the best rendering.