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
XDGViewer and GmDisplayViewer fail to show images #5976
Comments
When you use GmDisplayViewer, what error do you see? |
In case of GmDisplayViewer the image is not showing up, without reporting anything. |
If you modify your Pillow installation to include |
I think that I might have a better solution. :) |
I also suggest to have a look at Open multiple images case. This doesn't work as expected as well: try sliding through the images in a viewer. import os
from PIL import Image
if __name__ == "__main__":
img_dir = "path/to/img/directory"
img_files = ["file1.png", "file2.png", "file3.png"]
for img_file in img_files:
img_location = os.path.join(img_dir, img_file)
with Image.open(img_location) as im:
im.show(im) |
Just for the record - Could you expand on what problem you're seeing when showing multiple images? After inserting imageshow.mov |
Using either |
I believe that the perfect viewer function a) allows to open one image or multiple images in one script; b) multiple images can be viewed simultaneously, and user can switch from one image to another when viewing the images; c) image is closed when the user closes it in the viewer; d) temporary image files are deleted from the user machine. |
This also occurs with gwenview in KDE on KUbuntu versions as I posted here. |
Actually I fixed all the viewers, and I made a DisplayViewer (which is ImageMagick) the default viewer. I will make a PR today or tomorrow. |
OK, sounds good. Thanks! |
The user behind #5897 clearly had other thoughts, and so does a user in #5945 (comment). If there's not a solution that's going to make everyone happy, I'm inclined to leave the priority of |
This is a matter of system configuration of the |
I also have some thoughts regarding the viewers:
To summarize: the problem with UnixViewers is lack of consistency in the approach of how the things should work. The key questions to answer: 1) what kind of viewers to support? 2) how the viewing process needs to be handled? |
#6045 has now been merged, so in the next release of Pillow, images will now longer be remove on Unix. @BrettRyland regarding your request for the image viewer to be controlled from a configuration file on disk, Pillow doesn't use that technique for anything else at the moment. A similar idea is being discussed in #6070, but there is reluctance to move control of what is happening outside of the code. |
Fair enough. I understand the reluctance to implement a configuration file if that approach isn't being used anywhere else. I would suggest allowing the user to specify which viewer to use for the session in a simple single-line command that can be run early in a script or session (or put into |
Untested, but I believe the following example should do that: from PIL import ImageShow
from shlex import quote
class MyViewer(ImageShow.Viewer):
def get_command(self, file, **options):
return f"my-viewer {quote(file)}"
ImageShow.register(MyViewer(), order=0) |
That's not exactly a simple single-line command that the average user could be expected to use. from PIL import Image
# do some stuff to load or generate an image 'img'
img.show() I would think something along the lines of calling Image.set_show_options(command='display', tmp_file_removal_delay=3) after importing |
Just demonstrating some more alternatives that exist at present.
from PIL import Image, ImageShow
with Image.open("test.png") as im:
ImageShow.DisplayViewer().show(im)
from PIL import Image, ImageShow
ImageShow._viewers = [ImageShow.DisplayViewer()]
with Image.open("test.png") as im:
im.show() |
Note that Here's another alternative. https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.show
https://pillow.readthedocs.io/en/stable/reference/ImageShow.html#PIL.ImageShow.register
So, the user can do the following. from PIL import Image, ImageShow
ImageShow.register(ImageShow.DisplayViewer(), 0)
with Image.open("test.png") as im:
im.show() Edit: I now realise @nulano pointed this out already. I'm adding to that answer by demonstrating that it is documented, and that you don't need to create your own viewer if you just want to use one of the existing ones. That would seem to be a solution that is both simple and documented. Does that resolve this? |
#6045 sidesteps the issue of tmp file removal by simply not doing it, which can lead to a large build-up of tmp files if the system is rarely rebooted, though this is not really an issue on most systems unless the system in question is generating a lot of images this way. The point of The |
I've created PR #6078 to resolve this, by adding examples to the |
What did you do?
I created script to check Unix image viewers available in PIL.ImageShow module. The script example for XDGViewer is provided
below.
I run the script for all Linux/Unix viewers except XVViewer (I didn't manage to obtain it)
What did you expect to happen?
I expected to open my image with each single viewer I tried to use:
XDGViewer, DisplayViewer, GmDisplayViewer, EogViewer
What actually happened?
The image failed to open with
a) XDGViewer
b) GmDisplayViewer
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: