AOSSIE-Org / AOSSIE-Org/PictoPy

BUG: Thumbnail Generation Silently Fails for Certain PNG Modes

Open
#1,513 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
283
Forks
679
Avg merge
7d 2h
Merged PRs (30d)
3

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

## Images with certain colour modes silently missing from gallery

Images with certain PIL colour modes fail thumbnail generation silently. They are never inserted into the database and never appear in the gallery, with no error shown to the user.

### Root Cause

`image_util_generate_thumbnail` in `backend/app/utils/images.py` uses a denylist to decide when to convert the image before saving as JPEG:

```python
if img.mode in ("RGBA", "P"):
img = img.convert("RGB")

img.save(thumbnail_path, "JPEG")
```

Pillow's JPEG encoder natively supports only four modes: `RGB`, `L`, `CMYK`, `YCbCr`. The guard only catches `RGBA` and `P`, missing `LA` (greyscale + alpha), `I` (32-bit integer), and `F` (32-bit float) all valid and common image modes. For any of these, Pillow raises `cannot write mode X as JPEG`, `image_util_generate_thumbnail` returns `False`, the record is never written to the database, and the image is invisible to the user.

### Record

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.