How to update the image of a Tkinter Label widget?

The method label.configure does work in panel.configure(image=img). What I forgot to do was include the panel.image=img, to prevent garbage collection from deleting the image. The following is the new version: import Tkinter as tk import ImageTk root = tk.Tk() img = ImageTk.PhotoImage(Image.open(path)) panel = tk.Label(root, image=img) panel.pack(side=”bottom”, fill=”both”, expand=”yes”) def callback(e): img2 = ImageTk.PhotoImage(Image.open(path2)) panel.configure(image=img2) … Read more

Convert RGBA PNG to RGB with PIL

Here’s a version that’s much simpler – not sure how performant it is. Heavily based on some django snippet I found while building RGBA -> JPG + BG support for sorl thumbnails. from PIL import Image png = Image.open(object.logo.path) png.load() # required for png.split() background = Image.new(“RGB”, png.size, (255, 255, 255)) background.paste(png, mask=png.split()[3]) # 3 … Read more

How does perspective transformation work in PIL?

To apply a perspective transformation you first have to know four points in a plane A that will be mapped to four points in a plane B. With those points, you can derive the homographic transform. By doing this, you obtain your 8 coefficients and the transformation can take place. The site http://xenia.media.mit.edu/~cwren/interpolator/ (mirror: WebArchive), … Read more