Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log what file is raising error #14

Open
andreabisello opened this issue Jan 6, 2020 · 6 comments
Open

log what file is raising error #14

andreabisello opened this issue Jan 6, 2020 · 6 comments

Comments

@andreabisello
Copy link

optimizing a huge library of images,
one of this cannot be optimized.
i'm not able to understand what one.
i know the last optimized, but not the one working on.
this is the log


✅  [OPTIMIZED] ino-a-spirale-per-innaffiare-e-irrigare-piccole-superfici-forza-di-richiamo-diametro-9-mm-4647-202_.jpg
     JPG/RGB: 23.6 KB  ->  JPG/RGB: 19.4 KB 🔻 17.8%
✅  [OPTIMIZED] ino-a-spirale-per-innaffiare-e-irrigare-piccole-superfici-forza-di-richiamo-diametro-9-mm-4647-203_.jpg
     JPG/RGB: 40.1 KB  ->  JPG/RGB: 29.6 KB 🔻 26.2%concurrent.futures.process._RemoteTraceback:
"""
Traceback (most recent call last):
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\site-packages\PIL\JpegImagePlugin.py", line 628, in _save
    rawmode = RAWMODE[im.mode]
KeyError: 'P'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\concurrent\futures\process.py", line 239, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\concurrent\futures\process.py", line 198, in _process_chunk
    return [fn(*args) for args in chunk]
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\concurrent\futures\process.py", line 198, in <listcomp>
    return [fn(*args) for args in chunk]
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\site-packages\optimize_images\__main__.py", line 67, in do_optimization
    return optimize_jpg(t)
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\site-packages\optimize_images\img_optimize_jpg.py", line 70, in optimize_jpg
    quality, jpgdiff = jpeg_dynamic_quality(img)
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\site-packages\optimize_images\img_dynamic_quality.py", line 93, in jpeg_dynamic_quality
    normalized_diff = get_diff_at_quality(photo, 95)
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\site-packages\optimize_images\img_dynamic_quality.py", line 52, in get_diff_at_quality
    photo.save(diff_photo, format="JPEG", quality=quality, progressive=True)
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\site-packages\PIL\Image.py", line 2088, in save
    save_handler(self, fp, filename)
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\site-packages\PIL\JpegImagePlugin.py", line 630, in _save
    raise IOError("cannot write mode %s as JPEG" % im.mode)
OSError: cannot write mode P as JPEG
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Andrea-Fisso\AppData\Local\Programs\Python\Python37-32\Scripts\optimize-images.exe\__main__.py", line 9, in <module>
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\site-packages\optimize_images\__main__.py", line 97, in main
    for r in executor.map(do_optimization, tasks):
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\concurrent\futures\process.py", line 483, in _chain_from_iterable_of_lists
    for element in iterable:
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\concurrent\futures\_base.py", line 598, in result_iterator
    yield fs.pop().result()
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\concurrent\futures\_base.py", line 428, in result
    return self.__get_result()
  File "c:\users\andrea-fisso\appdata\local\programs\python\python37-32\lib\concurrent\futures\_base.py", line 384, in __get_result
    raise self._exception
OSError: cannot write mode P as JPEG


@victordomingos
Copy link
Owner

Isn’t it the same issue as #13?

@andreabisello
Copy link
Author

andreabisello commented Jan 6, 2020 via email

@victordomingos
Copy link
Owner

Oh, I see. There is no feedback on which image has caused the error.

Well, in this case, I think it would be better to catch the exception silently and move on. The user just wants all the images optimized if they can be optimized. If this utility can’t do the job, just leave the original image and let the user know the image was not optimized, as usual.

I can see it is complaining about a mode “P” image, so it must be a PNG. Can you please check if it happens with any of your color pallete mode PNG images?

@andreabisello
Copy link
Author

@victordomingos i agree.

so i should try with the -rc option?

@victordomingos
Copy link
Owner

As always, please be careful to work on copies, not original images. Then yes, feel free to experiment. "Reduce colors" may have quite a noticeable impact on perceived image quality, so it's something you eventualy may want to try apart just with a smaller set of images.

Can you please indicate which command-line options were you using when you got that error?

@andreabisello
Copy link
Author

@victordomingos i was using optimize-images ./

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants