Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#5386 closed defect (fixed)

PIL.Image.save() need format parameter when using file object

Reported by: 宋文武 Owned by:
Priority: major Milestone: 0.9.0
Component: programming Keywords:
Cc: Parent Tickets:

Description

Hi! when upload a jpg file, I got:

[...]
  File "...src/mediagoblin/mediagoblin/media_types/image/processing.py", 
line 125, in resize_tool
    quality, filter)
  File "...src/mediagoblin/mediagoblin/media_types/image/processing.py", 
line 81, in resize_image
    resized.save(resized_file, quality=quality)
  File "...lib/python3.4/site-packages/Pillow-3.0.0-py3.4-linux-x86_64.egg/PIL/Image.py", line 1649, in save
    format = EXTENSION[ext]
KeyError: ''
[...]

According to https://pillow.readthedocs.org/en/3.0.x/reference/Image.html?highlight=save#PIL.Image.Image.save
when use file object instead of filename, the format parameter should always be used.

Subtickets

Attachments (2)

Change History (9)

comment:1 Changed 5 years ago by Loic Dachary

Status: newaccepted

The modification looks good and is covered by the tests.

./runtests.sh --cov-report=term-missing --cov=mediagoblin mediagoblin/tests

mediagoblin/media_types/image/processing.py 190 65 66% 21-22, 71-72, 105-107, 137-151, 163-164, 245-246, 269, 282-307, 311, 337-342, 350-373, 377, 381-388, 398-404, 408-418, 422, 425-426, 436-446

Reviewed-by: Loic Dachary <loic@…>

comment:2 Changed 5 years ago by ShawnRisk

Status: acceptedreview

comment:3 Changed 5 years ago by 宋文武

Summary: Specify the format when save the resized imagePIL.Image.save() need format parameter when using file object

comment:4 Changed 5 years ago by 宋文武

I meet another one in media_types/ascii/processing.py.
Instead of pass file object, we can pass filename and PIL will figure out the format itself.
New patch attached.

comment:5 Changed 5 years ago by Christopher Allan Webber

Resolution: fixed
Status: reviewclosed

Okay, fine by me, if PIL can do just fine reading it on its own!

comment:6 Changed 5 years ago by Christopher Allan Webber

Milestone: 0.8.2

comment:7 Changed 5 years ago by Christopher Allan Webber

Milestone: 0.8.20.9.0

All 0.8.2 tickets are being rolled over to 0.9.0

Note: See TracTickets for help on using tickets.