Opened 10 years ago

Last modified 5 years ago

#5318 accepted defect

cannot write mode P as JPEG

Reported by: ayleph Owned by:
Priority: minor Milestone:
Component: programming Keywords: error, image, jpeg, rgb
Cc: Parent Tickets:

Description

A user tried to upload an image which produced the following error. A stackoverflow thread mentions converting to RGB space.

https://stackoverflow.com/questions/21669657/getting-cannot-write-mode-p-as-jpeg-while-operating-on-jpg-image

(mediagoblin-0.8.0) ~/mediagoblin $ bin/gmg reprocess run 4028 initial
DEBUG:mediagoblin.processing.task:Processing <MediaEntry 4028: otters>
ERROR:mediagoblin.processing.task:An unhandled exception was raised while processing <MediaEntry 4028: otters>
WARNING:mediagoblin.processing:No idea what happened here, but it failed: IOError('cannot write mode P as JPEG',)
WARNING:mediagoblin.processing:No idea what happened here, but it failed: IOError('cannot write mode P as JPEG',)
Traceback (most recent call last):
  File "bin/gmg", line 9, in <module>
    load_entry_point('mediagoblin==0.8.1.dev0', 'console_scripts', 'gmg')()
  File "/path/to/mediagoblin/mediagoblin/gmg_commands/__init__.py", line 142, in main_cli
    args.func(args)
  File "/path/to/mediagoblin/mediagoblin/gmg_commands/reprocess.py", line 293, in reprocess
    run(args)
  File "/path/to/mediagoblin/mediagoblin/gmg_commands/reprocess.py", line 205, in run
    reprocess_info=reprocess_request)
  File "/path/to/mediagoblin/mediagoblin/submit/lib.py", line 257, in run_process_media
    task_id=entry.queued_task_id)
  File "/path/to/mediagoblin/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/app/task.py", line 547, in apply_async
    link=link, link_error=link_error, **options)
  File "/path/to/mediagoblin/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/app/task.py", line 739, in apply
    request=request, propagate=throw)
  File "/path/to/mediagoblin/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/app/trace.py", line 355, in eager_trace_task
    uuid, args, kwargs, request)
  File "/path/to/mediagoblin/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/app/trace.py", line 253, in trace_task
    I, R, state, retval = on_error(task_request, exc, uuid)
  File "/path/to/mediagoblin/lib/python2.7/site-packages/celery-3.1.17-py2.7.egg/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/path/to/mediagoblin/mediagoblin/processing/task.py", line 101, in run
    processor.process(**reprocess_info)
  File "/path/to/mediagoblin/mediagoblin/media_types/image/processing.py", line 318, in process
    self.generate_thumb(size=thumb_size, filter=filter, quality=quality)
  File "/path/to/mediagoblin/mediagoblin/media_types/image/processing.py", line 221, in generate_thumb
    filter, size)
  File "/path/to/mediagoblin/mediagoblin/media_types/image/processing.py", line 125, in resize_tool
    quality, filter)
  File "/path/to/mediagoblin/mediagoblin/media_types/image/processing.py", line 81, in resize_image
    resized.save(resized_file, quality=quality)
  File "/path/to/mediagoblin/lib/python2.7/site-packages/PIL/Image.py", line 1682, in save
    save_handler(self, fp, filename)
  File "/path/to/mediagoblin/lib/python2.7/site-packages/PIL/JpegImagePlugin.py", line 571, in _save
    raise IOError("cannot write mode %s as JPEG" % im.mode)
IOError: cannot write mode P as JPEG

Change History (6)

comment:1 by ayleph, 9 years ago

Priority: majorminor

Changing priority as I only saw this issue once.

comment:2 by Loic Dachary, 9 years ago

Unless steps to reproduce the problem are added to this issue, it should probably be closed.

comment:3 by Ben Sturmfels, 8 years ago

Resolution: worksforme
Status: newclosed

I've spent some time trying to reproduce this issue, but no luck. I've tried various images including one with Adobe RGB colour space (as opposed to the more common sRGB).

I was able to make processing fail with a 1200x900 indexed PNG file (ie. one that needed resizing), but it didn't fail as above, so I'll create a separate ticket. Error was "OSError: cannot identify image file", re-raised as a BadMediaFail exception.

As Loic suggests, I'll close this as we can't reproduce it at this stage. Would love to hear if anyone comes up with an example that triggers this.

comment:4 by ayleph, 8 years ago

Okay with me. If I run across this again, I'll grab the image that causes it and share that in the ticket.

comment:5 by ayleph, 7 years ago

Resolution: worksforme
Status: closedaccepted

This just happened again. In this case it's a .gif that was named .gif.jpg prior to being uploaded.

Edit: the file was too large to attach to trac, so you can find it at the link below instead.

http://files.thisshitistemp.com/download/badimage.gif.jpg

Last edited 7 years ago by ayleph (previous) (diff)

comment:6 by Ben Sturmfels, 5 years ago

This is related to #5444. I'm starting to wonder whether filename should be used at all and whether it would be more robust to rely completely on sniffing.

Note: See TracTickets for help on using tickets.