MongoEngine / MongoEngine/mongoengine
Image Field put() silently compresses jpg images
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
The put() method of the ImageGridFsProxy opens and saves images before storing them to gridfs.
During saving of the image, as Image.save() is used without keyword arguments the default behavior for .jpg is a quality value of 75, as per Pillow documentation .
This leads to saving a significantly changed (compressed/ reduced quality compressed) version of the image. In my specific case this divides file-size by more than 4 and reduces the image quality visibly which I don't imagine is expected or mentioned anywhere.
I think this issue can be (relatively) easily sidestepped by duplicating the file before the Pillow operations and not saving with pillow at all but I might be missing something.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating ImageGridFsProxy.put and tracing its Image.save() call, then reproduce the behavior with a JPEG and compare the stored image with the original. Check the Pillow JPEG-saving behavior and existing image-field tests; done means storing a JPEG no longer silently applies the reported quality reduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100