Taiko2k / Avvie

A GTK app for quick image cropping :flower_playing_cards:
GNU General Public License v3.0
159 stars 19 forks source link

Cannot load any greyscale images #44

Open 0ion9 opened 1 year ago

0ion9 commented 1 year ago

The stated error occurs when opening any grayscale image. Unlike what you might suspect, the image does not have to have an alpha channel to cause this error; flattening it in GIMP makes no difference.

The log below is specifically the full error that occurs when attempting to open such a file on the commandline, ie avvie failing-image.png It is not clear to me why the second and third tracebacks both occur (they are identical to one another)

Traceback (most recent call last):
  File "/usr/share/avvie/avvie/main.py", line 151, in do_snapshot
    picture.load(self.avvie.to_load, (w, h))
  File "/usr/share/avvie/avvie/main.py", line 617, in load
    self.reload(keep_rect=self.rec_w > 0)
  File "/usr/share/avvie/avvie/main.py", line 554, in reload
    by = im.tobytes("raw", "RGBA")
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/PIL/Image.py", line 760, in tobytes
    e = _getencoder(self.mode, encoder_name, args)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/PIL/Image.py", line 437, in _getencoder
    return encoder(mode, *args + extra)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: No packer found from LA to RGBA

Traceback (most recent call last):
  File "/usr/share/avvie/avvie/main.py", line 1667, in toggle_menu_setting2
    picture.gen_thumbnails(hq=True)
  File "/usr/share/avvie/avvie/main.py", line 508, in gen_thumbnails
    by = cr.tobytes("raw", "RGBA")
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/PIL/Image.py", line 760, in tobytes
    e = _getencoder(self.mode, encoder_name, args)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/PIL/Image.py", line 437, in _getencoder
    return encoder(mode, *args + extra)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: No packer found from LA to RGBA

Traceback (most recent call last):
  File "/usr/share/avvie/avvie/main.py", line 1667, in toggle_menu_setting2
    picture.gen_thumbnails(hq=True)
  File "/usr/share/avvie/avvie/main.py", line 508, in gen_thumbnails
    by = cr.tobytes("raw", "RGBA")
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/PIL/Image.py", line 760, in tobytes
    e = _getencoder(self.mode, encoder_name, args)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/PIL/Image.py", line 437, in _getencoder
    return encoder(mode, *args + extra)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: No packer found from LA to RGBA

The overall result is that any grayscale image simply cannot be cropped in Avvie without first converting it to RGB(A).

Avvie v 2.2 (installed via AUR package 'avvie') Python 3.11 Pillow 9.5.0 Example failing image: Attached. failing-image

Taiko2k commented 1 year ago

OK Ive committed a change so it will convert the image to RGB format so it will work. Not sure if that's too lazy or not or if anyone cares.

Ill probably get around to doing a release soon.

0ion9 commented 1 year ago

Ideally you'd record the input pixel format and save with that, but yeah, optipng will figure out that the file can be reduced to greyscale, so it's no big deal, mostly. (not sure whether, for WEBP, there is any utility that will do the same kind of detection->optimization.)