Opened 5 years ago

Last modified 2 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

Subtickets

Change History (5)

comment:1 Changed 4 years ago by ayleph

Priority: majorminor

Changing priority as I only saw this issue once.

comment:2 Changed 4 years ago by Loic Dachary

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

comment:3 Changed 3 years ago by Ben Sturmfels

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 Changed 3 years ago by ayleph

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 Changed 2 years ago by ayleph

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 2 years ago by ayleph (previous) (diff)
Note: See TracTickets for help on using tickets.