Code Monkey home page Code Monkey logo

optimize-images's People

Contributors

dependabot[bot] avatar derenix avatar liashchynskyi avatar truethari avatar varnav avatar victordomingos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

optimize-images's Issues

skip optimization on error, don't exit process

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


Allow command for optimizing single file with --output name specified

This kind of tool usually has an optional command line available like this:

tool --output my_output_image.png my_input_image.png

This is very useful, especially in cases where you want to keep the original un-optimized file.

Another form would be

tool source_dir --output-dir destination_dir

where it is understood that all files found recursively under source_dir will be converted to the same dir under destination_dir.

Specify Pillow as requirement in setup.py?

PIL hasn't been updated since [2009](http://www.pythonware.com/products/pil/#pil117), whereas [pillow](https://pillow.readthedocs.io/) is under active development.

I think it would be a good idea to change, especially as you are using Python >= 3.6.

I can put in a pull request if you wish.

This is a nice little utility which has saved me writing my own :) Thanks.

Convert png to jpg regardless of size

Would love to batch convert all pngs to jpgs and force delete original as part of my optimize/resize process. I tried using optimize-images -cb -fd ./ but it did not convert my pngs which were 660kb.

Log

Hi
Can a option be added to create a log file for the optimized images.

log what file is raising error

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


Brunsli support?

Brunsli is a lossless JPEG repacking library.

Brunsli allows for a 22% decrease in file size while allowing the original JPEG to be recovered byte-by-byte.

Is it possible to add support for it?

Skips png's

Describe the bug
The app skips pngs by default
In de readme it says: "tries to optimize each encoder's settings for maximum space reduction and applies the maximum ZLIB compression on PNG.", But in reality it just says:

🔴  [SKIPPED] redacted.png                                                                                      
----------------------------------------

   Processed 1 files (1.2 MB) in 3.0s (0.3 f/s).
   Optimized 0 files.
   Average savings: 0.0 B per optimized file
   Total space saved: 0.0 B / 0.0%

To Reproduce
Steps to reproduce the behavior:

  1. optimize-images mypng.png
  2. ???
  3. Profit

Expected behavior
A smaller png

Desktop (please complete the following information):

  • OS: Manjaro 21.0.2 Ornara
  • Python 3.9
  • Optimize Images version 1.4.0

Keep Image resolution (DPI)

After compressing, the resolution goes down - in my case from 300 to 72 (DPI) . Can you please allow an option for keeping the image resolution the same

Read-only file system /~temp~image.png

Hi, I've found that this tools doesn't work for me on MacOS:

I'm using the following command:
optimize-images -rc -q 70 image.png

Results:

Using these symbols:

  ✅ Optimized file     ℹ️  EXIF info present
  🔴 Skipped file       ⤵  Image was downsized     🔻 Size reduction (%)

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/optimize_images/img_optimize_png.py", line 125, in optimize_png
    img.save(temp_file_path, optimize=True, format=result_format)
  File "/usr/local/lib/python3.7/site-packages/PIL/Image.py", line 2085, in save
    fp = builtins.open(filename, "w+b")
OSError: [Errno 30] Read-only file system: '/~temp~image.png'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/optimize-images", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/optimize_images/__main__.py", line 134, in main
    r = do_optimization(img_task)
  File "/usr/local/lib/python3.7/site-packages/optimize_images/__main__.py", line 66, in do_optimization
    return optimize_png(t)
  File "/usr/local/lib/python3.7/site-packages/optimize_images/img_optimize_png.py", line 128, in optimize_png
    img.save(temp_file_path, optimize=True, format=result_format)
  File "/usr/local/lib/python3.7/site-packages/PIL/Image.py", line 2085, in save
    fp = builtins.open(filename, "w+b")
OSError: [Errno 30] Read-only file system: '/~temp~image.png'

Why this tool tried to use / directory to save temporary images?

PIL.UnidentifiedImageError: cannot identify image file

Hello,

This issue is similar to #13

I try to use optimize-images cli on Ubuntu to recursively optimize images, it happens suddenly that I get this error:

PIL.UnidentifiedImageError: cannot identify image file

when I try to only optimize the image in question I get the same error, so the error is in the image itself, when I check its type and details I get that:
JPEG image data, JFIF standard 1.01, resolution (DPI), density 96x96, segment length 16, Exif Standard: [TIFF image data, big-endian, direntries=23, height=0, bps=0, compression=LZW, PhotometricIntepretation=RGB, manufacturer=Canon, model=Canon EOS 5DS R, orientation=upper-left, width=0]

# python -V
Python 3.6.10
# optimize-images -v
1.3.5
NAME="Ubuntu"
VERSION="16.04.5 LTS (Xenial Xerus)"

My question here, why the software refusing to optimize this image and how can I make it ignore and continue because if it finds an error it just stops, I want it to ignore that error and continue working on the rest.

Best regards,

Claims Pillow isn't installed while it is?

Describe the bug
Installed this on an updated RaspiOS install on RPI Zero. Running the app tells me to install Pillow even though it's installed?

To Reproduce
Steps to reproduce the behavior:

  1. install on rpi zero with raspiOS lite
  2. run command
  3. get error

Expected behavior
I expect to optimize the JPEGs in the given directory.

Screenshots

pi@camerapi:~/images/ledsON $ optimize-images -nr ./

    This application requires Pillow to be installed. Please, install it first.

pi@camerapi:~/images/ledsON $ pip3 install pillow
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pillow in /home/pi/.local/lib/python3.7/site-packages (8.1.0)

pi@camerapi:~/images/ledsON $ optimize-images -nr ./

    This application requires Pillow to be installed. Please, install it first.

Desktop (please complete the following information):

  • OS: Linux 5.10.11+ #1399 armv6l GNU/Linux
  • Python version: Python 3.7
  • Optimize Images version: latest

Additional context
Add any other context about the problem here. If issue happens with a specific image file, if possible please attach a sample file (please make sure you don't upload any confidential image or information).

Skip non-image file types

Script crashes when it tries to process .pdf files in same folder as .jpg or .png - would be nice if it would just skip these and carry on.

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

Traceback (most recent call last):
File "c:\users\wbarrie\appdata\local\programs\python\python37\lib\runpy.py", line 193, in run_module_as_main
"main", mod_spec)
File "c:\users\wbarrie\appdata\local\programs\python\python37\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Users\wbarrie\AppData\Local\Programs\Python\Python37\Scripts\optimize-images.exe_main
.py", line 7, in
File "c:\users\wbarrie\appdata\local\programs\python\python37\lib\site-packages\optimize_images_main
.py", line 97, in main
for r in executor.map(do_optimization, tasks):
File "c:\users\wbarrie\appdata\local\programs\python\python37\lib\concurrent\futures\process.py", line 483, in _chain_from_iterable_of_lists
for element in iterable:
File "c:\users\wbarrie\appdata\local\programs\python\python37\lib\concurrent\futures_base.py", line 598, in result_iterator
yield fs.pop().result()
File "c:\users\wbarrie\appdata\local\programs\python\python37\lib\concurrent\futures_base.py", line 428, in result
return self.__get_result()
File "c:\users\wbarrie\appdata\local\programs\python\python37\lib\concurrent\futures_base.py", line 384, in __get_result
raise self._exception
PIL.UnidentifiedImageError: cannot identify image file './danby\refrigerators-and-freezers\DCR031B1BSLDD\DCR031B1BSLDD-product-specs.jpg'` <- this is actually a .pdf

Impressive. But what exactly it does to my files?

There is no clear documentation what exactly this script does. If I run it on directory I see impressive optimizations, like twice better than what jpegoptim does, and way faster. But I'm afraid to run it over my photo collection, as I can't understand what it does to images. While it's pretty clear what jpegoptim does.

Can you please clarify in the docs what exactly it does to jpeg files if I run it on directory? Like "if image is bigger that 4000x3000 reduce it to 4000x3000", "strip all EXIF information" "apply lossless optimizations", etc.

Command line icons not properly shown in Windows

The red dot, the green check mark, and the red triangle do not show up properly in the command line of Windows. (I'm referring to the screenshot in your README file.)

Can you use ASCII characters instead? Thanks.

img_optimize_png.py not parsing temp path correctly

Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/optimize_images/img_optimize_png.py", line 125, in optimize_png
img.save(temp_file_path, optimize=True, format=result_format)
File "/usr/local/lib/python3.7/site-packages/PIL/Image.py", line 1966, in save
fp = builtins.open(filename, "w+b")
PermissionError: [Errno 13] Permission denied: '/tempwoocommerce-placeholder.png'

Destroys EXIF data despite --keep-exif

Describe the bug
Destroys EXIF data despite --keep-exif

To Reproduce

pip3 install pillow optimize-images
optimize-images --keep-exif .

Optimized image will have it's EXIF data wiped.

Expected behavior
Image gets optimized, EXIF data intact.

UnboundLocalError: local variable 'has_exif' referenced before assignment

Describe the bug
A clear and concise description of what the bug is.

I have a folder that have EXIF and non-exif photos. While running, this error happens:

optimize-images --keep-exif folder/

oncurrent.futures.process._RemoteTraceback:
"""
Traceback (most recent call last):
  File "/mnt/f/linux/miniconda3/lib/python3.9/concurrent/futures/process.py", line 243, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "/mnt/f/linux/miniconda3/lib/python3.9/concurrent/futures/process.py", line 202, in _process_chunk
    return [fn(*args) for args in chunk]
  File "/mnt/f/linux/miniconda3/lib/python3.9/concurrent/futures/process.py", line 202, in <listcomp>
    return [fn(*args) for args in chunk]
  File "/mnt/f/linux/miniconda3/lib/python3.9/site-packages/optimize_images/do_optimization.py", line 34, in do_optimization
    return optimize_jpg(task)
  File "/mnt/f/linux/miniconda3/lib/python3.9/site-packages/optimize_images/img_optimize_jpg.py", line 101, in optimize_jpg
    has_exif)
UnboundLocalError: local variable 'has_exif' referenced before assignment
"""

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

Traceback (most recent call last):
  File "/mnt/f/linux/miniconda3/bin/optimize-images", line 8, in <module>
    sys.exit(main())
  File "/mnt/f/linux/miniconda3/lib/python3.9/site-packages/optimize_images/__main__.py", line 154, in main
    optimize_batch(*args)
  File "/mnt/f/linux/miniconda3/lib/python3.9/site-packages/optimize_images/__main__.py", line 108, in optimize_batch
    for result in executor.map(do_optimization, tasks):
  File "/mnt/f/linux/miniconda3/lib/python3.9/concurrent/futures/process.py", line 559, in _chain_from_iterable_of_lists
    for element in iterable:
  File "/mnt/f/linux/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 600, in result_iterator
    yield fs.pop().result()
  File "/mnt/f/linux/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 440, in result
    return self.__get_result()
  File "/mnt/f/linux/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 389, in __get_result
    raise self._exception
UnboundLocalError: local variable 'has_exif' referenced before assignment

Screenshots
If applicable, add screenshots or traceback from console (please redact any confidential info) to help explain your problem.

Desktop (please complete the following information):
WSL2, the latest optimize-images, works without --keep-exif

Crashes when meets it's own temp file

I often get errors like this:

✅  [OPTIMIZED] .\22may_shaslyk\22may_shaslyk 051.jpg
     JPG/RGB: 622.0 KB  ->  JPG/RGB: 345.3 KB 🔻 44.5%concurrent.futures.process._RemoteTraceback:
"""
Traceback (most recent call last):
  File "c:\users\someone\appdata\local\programs\python\python37\lib\shutil.py", line 566, in move
    os.rename(src, real_dst)
FileExistsError: [WinError 183] Невозможно создать файл, так как он уже существует: '.\\22may_shaslyk/~temp~22may_shaslyk 052.jpg' -> '.\\22may_shaslyk\\22may_shaslyk 052.jpg'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\someone\appdata\local\programs\python\python37\lib\concurrent\futures\process.py", line 239, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
  File "c:\users\someone\appdata\local\programs\python\python37\lib\concurrent\futures\process.py", line 198, in _process_chunk
    return [fn(*args) for args in chunk]
  File "c:\users\someone\appdata\local\programs\python\python37\lib\concurrent\futures\process.py", line 198, in <listcomp>
    return [fn(*args) for args in chunk]
  File "c:\users\someone\appdata\local\programs\python\python37\lib\site-packages\optimize_images\__main__.py", line 67, in do_optimization
    return optimize_jpg(t)
  File "c:\users\someone\appdata\local\programs\python\python37\lib\site-packages\optimize_images\img_optimize_jpg.py", line 104, in optimize_jpg
    shutil.move(temp_file_path, os.path.expanduser(t.src_path))
  File "c:\users\someone\appdata\local\programs\python\python37\lib\shutil.py", line 580, in move
    copy_function(src, real_dst)
  File "c:\users\someone\appdata\local\programs\python\python37\lib\shutil.py", line 266, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "c:\users\someone\appdata\local\programs\python\python37\lib\shutil.py", line 121, in copyfile
    with open(dst, 'wb') as fdst:
OSError: [Errno 22] Invalid argument: '.\\22may_shaslyk\\22may_shaslyk 052.jpg'
"""

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

Traceback (most recent call last):
  File "c:\users\someone\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\someone\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\someone\AppData\Local\Programs\Python\Python37\Scripts\optimize-images.exe\__main__.py", line 9, in <module>
  File "c:\users\someone\appdata\local\programs\python\python37\lib\site-packages\optimize_images\__main__.py", line 96, in main
    for r in executor.map(do_optimization, tasks):
  File "c:\users\someone\appdata\local\programs\python\python37\lib\concurrent\futures\process.py", line 483, in _chain_from_iterable_of_lists
    for element in iterable:
  File "c:\users\someone\appdata\local\programs\python\python37\lib\concurrent\futures\_base.py", line 598, in result_iterator
    yield fs.pop().result()
  File "c:\users\someone\appdata\local\programs\python\python37\lib\concurrent\futures\_base.py", line 435, in result
    return self.__get_result()
  File "c:\users\someone\appdata\local\programs\python\python37\lib\concurrent\futures\_base.py", line 384, in __get_result
    raise self._exception
OSError: [Errno 22] Invalid argument: '.\\22may_shaslyk\\22may_shaslyk 052.jpg'

Looks like it's a race condition. It's less likely to happen if system is under load. I'm running under Windows 10.

Allow export to format ".webp"

Great tool!
I just missed the possibility of specifying the output format, would I have the possibility of becoming a feature?

AttributeError: 'NoneType' object has no attribute 'orig_size'

λ optimize-images /Users/anthony/Downloads/4064VH-PWCopy/4064VH-PW_001.jpg

Using these symbols:

✅ Optimized file ℹ️ EXIF info present
🔴 Skipped file ⤵ Image was downsized 🔻 Size reduction (%)

Traceback (most recent call last):
File "c:\users\anthony\appdata\local\programs\python\python37-32\lib\runpy.py", line 193, in run_module_as_main
"main", mod_spec)
File "c:\users\anthony\appdata\local\programs\python\python37-32\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Users\anthony\AppData\Local\Programs\Python\Python37-32\Scripts\optimize-images.exe_main
.py", line 9, in
File "c:\users\anthony\appdata\local\programs\python\python37-32\lib\site-packages\optimize_images_main
.py", line 115, in main
total_src_size = r.orig_size
AttributeError: 'NoneType' object has no attribute 'orig_size'

Ability to Suppress Output

Is your feature request related to a problem? Please describe.
I want to run the utility without any output unless an error occurs

Describe the solution you'd like
Command line option to suppress output

Additional context
This utility is being called from within another program with logging enabled. This will quickly increase the size of the log without any benefit. The display of errors should still occur.

Optimize Images 1.5.0

Running environment:

  • Location: /usr/local/bin/optimize-images
  • Pillow 8.3.2
  • Piexif 1.1.3
  • Python 3.7.3 (/usr/bin/python3)

Optional packages:

  • Watchdog 2.1.2

Catch more exceptions when Exif broken

Hi,
Thanks for providing this useful tool, I'm using it to generate compressed images in NAS devices.

had_exif = True if piexif.load(t.src_path)['Exif'] else False

The 'piexif.load()' you used to get exif may raise a lot of different exceptions when exif head is broken(e.g. struct.error: unpack requires a buffer of n bytes). The program need to catch those, otherwise it will corrupted.

Support HEIC/HEVC format?

I accept images from camera iPhones, the HEIC images are so large, that I would like to optimize them before saving them to the server. Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.