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

Allow PhotoImage objects as image-data. #162

Closed
Netzeband opened this Issue May 12, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@Netzeband

Netzeband commented May 12, 2017

Hi,

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.
It allows to pass a PhotoImage object, created by PIL.ImageTk to the addImageData and setImageData method of appJar. In this way you can use any source you want as image. An example usage would be:

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 <netzeban@hm.edu>
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?

@jarvisteach

This comment has been minimized.

Show comment
Hide comment
@jarvisteach

jarvisteach May 24, 2017

Owner

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!

Owner

jarvisteach commented May 24, 2017

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!

@jarvisteach jarvisteach modified the milestone: 0.08 May 29, 2017

jarvisteach added a commit that referenced this issue Aug 11, 2017

PhotImage objects now supported (#162)
Included patch from @Netzeband to allow PhotoImage objects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment