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

skip optimization on error, don't exit process #13

Closed
andreabisello opened this issue Jan 6, 2020 · 1 comment
Closed

skip optimization on error, don't exit process #13

andreabisello opened this issue Jan 6, 2020 · 1 comment

Comments

@andreabisello
Copy link

optimizing a folder of images,
one of these image raise an error and entire process exits.
i suggest to keep optimization on other images.

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

@andreabisello I have been doing small changes that should have solved this issue. Please check out the current version on GitHub, which is slightly ahead of PyPI.

I am closing this issue for now, but in case there are still any problems please let me know.

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