-
-
Notifications
You must be signed in to change notification settings - Fork 545
Fix thumbnail generation crash after resizing #1982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix thumbnail generation crash after resizing #1982
Conversation
|
I appreciate you contributing to Misago, but can you please finish addressing one PR review before opening the next one? I've left you bunch of comments in #1980 that still need addressing. Thanks! |
misago/attachments/thumbnails.py
Outdated
| "WEBP": "image/webp", | ||
| "TIFF": "image/tiff", | ||
| "BMP": "image/bmp", | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong way to go about this. Pillow already knows what format image is, via image.format attribute. It just loses this attribute when it downscales initial image if it's too big. We should find a way to keep this initial image.format attribute instead of introducing extra logic.
|
The good way to go about this is: Add Update |
Thanks for the hint! I'll update accordingly |
45c5b5e to
136fe33
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs two tests:
- Uploaded attachment with width greater than
max_width - Ditto, but height greater than
max_height
misago/attachments/management/commands/processimageattachments.py
Outdated
Show resolved
Hide resolved
| pytest.param(400, 1000, id="max_width_greater"), | ||
| ], | ||
| ) | ||
| def test_generate_attachment_thumbnail_generates_thumbnail_image_and_updates_attachment_gt_max_dimensions( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function that you should test is store_uploaded_file, not generate_attachment_thumbnail
|
Hi @rafalp |
|
Merged as part of #2013, thank you <3 |
Fixes #1976
Fix thumbnail generation crash when Pillow drops image.format after resizing.
Preserve original image_format in upload pipeline and fall back safely to PNG when missing.