Opened 8 years ago

Closed 8 years ago

Last modified 8 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.

Attachments (2)

Change History (9)

comment:1 by Loic Dachary, 8 years ago

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 by ShawnRisk, 8 years ago

Status: acceptedreview

comment:3 by 宋文武, 8 years ago

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

comment:4 by 宋文武, 8 years ago

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 by Christopher Allan Webber, 8 years ago

Resolution: fixed
Status: reviewclosed

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

comment:6 by Christopher Allan Webber, 8 years ago

Milestone: 0.8.2

comment:7 by Christopher Allan Webber, 8 years ago

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.