Join GitHub today
Allow PhotoImage objects as image-data. #162
at the moment, appJar can only show gif and png images. However, sometimes you have an image in Memory and you simply want to show this in appJar.
The following patch with two very small changes enables this usecase.
from PIL import Image as pil from PIL import ImageTk as piltk # MyImage is a numpy-array containing a RGB image PilImage = pil.fromarray(MyImage, 'RGB') PilImage = piltk.PhotoImage(PilImage) GUI.addImageData("Recorded Image", PilImage, fmt="PhotoImage")
This is the patch:
From d781bb836300d83302fbb1aefbf54024b30f2576 Mon Sep 17 00:00:00 2001 From: Andre <firstname.lastname@example.org> Date: Fri, 12 May 2017 22:58:52 +0200 Subject: [PATCH] Allow PhotoImage-Objects as input for images. --- appJar/appjar.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/appJar/appjar.py b/appJar/appjar.py index dcfa81c..008b862 100755 --- a/appJar/appjar.py +++ b/appJar/appjar.py @@ -4429,9 +4429,13 @@ class gui(object): else: raise Exception("PNG images only supported in python 3: " + imagePath) - else: + elif fmt=="gif": imgObj = PhotoImage(data=imageData) + else: + # expect we already have a PhotoImage object, for example created by PIL + imgObj = imageData + imgObj.path = None imgObj.modTime = datetime.datetime.now() imgObj.isAnimated = False @@ -4529,9 +4533,9 @@ class gui(object): def reloadImageData(self, name, imageData): self.setImageData(name, imageData) - def setImageData(self, name, imageData): + def setImageData(self, name, imageData, fmt="gif"): label = self.__verifyItem(self.n_images, name) - image = self.__getImageData(imageData) + image = self.__getImageData(imageData, fmt=fmt) self.__populateImage(name, image) # replace the current image, with a new one -- 2.11.1.windows.1
Maybe this patch can be included into the mainline?
Thank you so much for this! I'm planning on adding in support for PIL in an upcoming release - so if PIL is installed, appJar will use that, instead of the built in image handling code. That will help resolve a couple of outstanding issues with images. So, I will look at this patch at that time, but it looks like the sort of thing we need!