victordomingos / optimize-images

A command-line interface (CLI) utility written in pure Python to help you reduce the file size of images.
https://no-title.victordomingos.com/projects/optimize-images
MIT License
269 stars 49 forks source link

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

Closed TimurNurlygayanov closed 4 years ago

TimurNurlygayanov commented 4 years ago

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?

TimurNurlygayanov commented 4 years ago

Update: it works fine if I specify the full path to the file

victordomingos commented 4 years ago

I will look into that. Can you please tell me which version are you using? Can you test it with the current development master from Github?

TimurNurlygayanov commented 4 years ago

I'm using 1.35 version installed with pip3, MacOS 10.15.4

optimize-images -v
1.3.5
victordomingos commented 4 years ago

Hi. In fact the current PyPI.org version does not include a fix that I believe was introduced in ad0aee7. Just needs some additional testing before submission to PyPI. Please stay tuned for the next release.

Meanwhile, in case you are able to test the current development version, please report if it solved the issue for you. You can find some instructions on the full documentation page:

victordomingos commented 4 years ago

Actually, it seems it had been solved only for JPEG files. I have just submitted the same fix for PNG files. It will also be included in the next PyPI update, but can be obtained right now from this repo.

To install the current development version (just replace python3.8 with your python version):

python3.8 -m pip install git+https://github.com/victordomingos/optimize-images

This is the version I am currently working on.

victordomingos commented 3 years ago

Just a quick notice to let you know that, on the latest commit (not yet available in PyPI), I have implemented in-memory buffers using BytesIO, instead of in-disk temporary files.

TimurNurlygayanov commented 3 years ago

Cool! Thank you!