Can not imwrite a JPG with e.g. ".part" suffix
See original GitHub issue@FirefoxMetzger Hey, in 2.11.0 and later, I can not write a JPG with a “.part” suffix. This is with current master:
(testenv) estan@edison:~$ python3 -c 'from imageio import imwrite; imwrite("/tmp/a.jpg.part", [[[1,1,1]]], format="jpg")'
Traceback (most recent call last):
File "/home/estan/imageio/imageio/core/imopen.py", line 188, in imopen
return loader(request, **kwargs)
File "/home/estan/imageio/imageio/core/imopen.py", line 177, in loader
return config.plugin_class(request, **kwargs)
File "/home/estan/imageio/imageio/config/plugins.py", line 108, in partial_legacy_plugin
return LegacyPlugin(request, legacy_plugin)
File "/home/estan/imageio/imageio/core/legacy_plugin_wrapper.py", line 74, in __init__
raise InitializationError(
imageio.core.request.InitializationError: `JPEG-PIL` can not write to `/tmp/a.jpg.part`.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/estan/imageio/imageio/v2.py", line 195, in imwrite
with imopen(uri, "wi", plugin=format) as file:
File "/home/estan/imageio/imageio/core/imopen.py", line 206, in imopen
raise err_type(err_msg) from err_from
RuntimeError: `jpg` can not handle the given uri.
(testenv) estan@edison:~$
This used to work fine with 2.10.5 and earlier versions.
If I pass format="jpg"
to imwrite then I expect it to not care about the output file suffix.
Issue Analytics
- State:
- Created a year ago
- Comments:16 (12 by maintainers)
Top Results From Across the Web
cv::imwrite could not find a writer for the specified extension
I faced the same error and I hadn't specified the extension or image format with the filename. This is the correct answer in...
Read more >Reading and saving image files with Python, OpenCV (imread ...
In Python and OpenCV, you can read (load) and write (save) image files with cv2.imread() and cv2.imwrite(). Images are read as NumPy array ......
Read more >MATLAB imwrite - Write image to graphics file
This MATLAB function writes image data A to the file specified by filename, inferring the file format from the extension.
Read more >imageiov2.10.1. The imwrite will raise ValueError when ...
It seems that there is no need to maintain a new constant. Replace. parts = urlparse(self._filename) ext = Path(parts.path).suffix.lower().
Read more >OpenCV: Image file reading and writing
imwrite () Saves an image to a specified file. The function imwrite saves the image to the specified file. The image format is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@almarklein In this case, how about calling it
extension
as inMy main concern about
format
is that the name is easily misunderstood as dictating the format. This would only be true when writing with backends that support more than one format (so far they all decide the encoder to use based on the extension), but would be false for backends that support only one format (they simply write that format regardless of extension). It would also be false when reading anything (backends check the file header and ignore the extension). A name likeextension
orignore_extension=False
would be more explicit and avoid this false perception.Plus one for me!
Some thoughts: we might also consider a different approach for reading and writing. When writing a file, the user defines what to write. This is the extension by default, but indeed specifying a format should use that given format, i.e. by authoritative.
For reading, it’s different, because the file is already in a specific format. We have mechanics in place to try and auto-detect the format, but need a way for the user to specify the format when it fails. A (non-athorative) hint seems nice, but what if it’s ignored (imageio keeps using the extension) and it still fails? There is more room for discussion here, but I think it should be authoritative for reading as well …