when I display an image with PIL Image it opens an imagemagick window but the title is some gibberish name like 'tmpWbfj48Bfjf'. How do I make the image filename to be the title of the viewer window?
Use the title attribute: Image.show(title="Your Title Here" [...]
From the documentation:
Image.show(title=None, command=None) Displays this image. This method
is mainly intended for debugging purposes.
On Unix platforms, this method saves the image to a temporary PPM
file, and calls the xv utility.
On Windows, it saves the image to a temporary BMP file, and uses the
standard BMP display utility to show it (usually Paint).
Parameters: title – Optional title to use for the image window, where
possible. command – command used to show the image
Related
I want to display a short manual in a tab of program
(Windows 10, anaconda distribution, python 3.7.6, pyqt 5.12).
I wrote a text document with html inside and load it in a QTextEdit using
self.te_short_manual = QTextEdit() # Textedit for display
with open(os.path.join(py_file_folder, r"doc_files\tab5_documentation.html"), "r") as doc_file:
lines = doc_file.readlines()
doc_text = "\n".join(lines)
self.te_short_manual.setHtml(doc_text)
self.te_short_manual.setReadOnly(True)
In the text document I use the img command to load an image:
<p>
<img src="banana_select_roi_nb2.tif" alt="Safely selecting a ROI" width="500" >
<br>FIG 1: <i>How to use the color map limits to better define the ROI.</i>
</p>
Using this image image_faisceau_ 28.tif, I see the image as wished (but not in Firefox).
Using this image banana_select_roi_nb.tif, I do not see the image (in Firefox neither).
Using this image IR_0309.jpg, I do not see the image (but I see it in Firefox).
All images and the text document are in the same directory.
I read about QWebView here
Display HTML file with image in QTextEdit, but would like to avoid it.
Running supportedImageFormats() shows a long list including tif, tiff, jpg, png, ... formats
https://forum.qt.io/topic/54924/solved-a-png-image-within-html-code-in-a-qtextedit
reported something similar with the image not showing in firefox when showing in QTextEdit,
but adding "html/" in the src-value did not help. There is still this kind of placeholder displayed... and anyway, one of the two tif-images works.
In addition to some help to solve the problem on my machine, comments on the expected robustness
off my apporach would be appreciated. I wonder what happens if I give the program to somebody else. Ideally I would like it to work on all standard Anaconda installs.
I'm trying to open an image with WIndows Live Photo Gallery.
The image has path:
C:\Users\User\Desktop\Image.jpg
I want to open it at the beginning of the loop and then close it a the end of the loop.
I've successfully managed to open it with:
img = os.startfile("image.jpg")
However I can't seem to find any way to close the image at the end of the loop.
Also if any of you know any better way to call and then close an image (it doesn't need to be with Windows Live Photo Viewer).
you better install Python Pillow module
from PIL import Image
im = Image.open(r"C:\Users\System-Pc\Desktop\bla.jpg")
im.show()
when done use im.close()
I want my python script so save the python window as a .JPG, which it does. But when I try and open that .jpg with any application it tells me the file type is unsupported.
When I save my file as a .eps file it opens correctly but when I try and save as any other file type the file will not open.
win.postscript(file="image.jpg", colormode='color')
from PIL import Image as NewImage
img = NewImage.open("image.jpg")
Tkinter canvas object can only be saved as a postscript file, which is actually a postscript printer language text file.
Thus if you call:
win.postscript(file="image.jpg", colormode='color')
It will still write and create a postscript file, that is why it works when you rename the extension [or simply append] with .ps
Check this blog for a better implementation: https://www.daniweb.com/programming/software-development/code/216929/saving-a-tkinter-canvas-drawing-python
I am trying to open an image using python; I wrote the following code :
from PIL import Image
im=Image.open("IMG_1930.jpg")
im.show()
But the windows photo viewer opens but it shows the following message instead of the photos:
"windows photo viewer can not open this picture because either the picture is deleted , or it isn't in a location that is accessible."
The show method in PIL is a poor's man way of viewing an image - it has got a hardcoded image viewer application, and writes your image data to a temporary file before calling that as an external application.
What is happening there is that you are either having problems with Windows' uneven access rights policies, and the viewer can't open the file in Python's temporary directory, or there is a problem with Window's problematic path specifications - it might even be a bug in PIL, that renders the temporary paht generated by PIL unusable by the image viewer.
If you are using show in a windowing application, use your tookit's way of viewing images to display it instead - otherwise, if it is a simpler application, build up a Tkitner Window and put the image in it, instead of show.
import sys
import Tkinter
from PIL import Image, ImageTk
window = Tkinter.Tk()
img = Image.open("bla.png")
img.load()
photoimg = ImageTk.PhotoImage(img)
container = Tkinter.Label(window, image=photoimg)
container.pack()
Tkinter.mainloop()
(Linux users: some distributions require the separate install of Tkinter support for PIL/PILLOW. In Fedora, for example, one has to install the python-pillow-tk package )
I also had problems with this. Take a look at this post it fixed my problem: PIL image show() doesn't work on windows 7
Good luck fixing it.
Through a python program, i am generating some SVG images. Each of this SVG Image has an external PNG Image attached to it.
Individually all these SVG images are good and look perfect.
But then i am creating a master SVG, which contains all these previously created SVG images (linked via image tag). When i view the master SVG in inkscape (on ubuntu), the PNG images are not displaying.
Can anyone suggest what is the problem?
NOTE: All Images (SVG and PNG) are linked by absolute paths on the system.
If you're using an SVG image via the <image> tag then it must be complete in a single file i.e. it can't link to an external png file.
You could convert the png file to a data URL and embed it in the SVG image file.