Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Clipboard.get_image Crash in Pythonista Keyboard
-
It seems Clipboard.get_image Can’t handle a large image (900kb in my case) in Pythonista Keyboard. Is there any workarounds?Thanks.
-
@mieq could you post your code please. 900 kB is not big
-
@cvp Just a simple Code like the following, and set as Pythonista Keyboard script. copy a 900kb image, run it in the Pythonista Keyboard and crash.the image under 500kb is all right.
import clipboard clipboard.get_image() print('Done')
-
@mieq it seems that you're right, no explanation. Doc says that we can use keyboard for simple things. Perhaps a big image is not so simple 😀
-
-
@mieq the problem comes from the clipboard.get_image because you can use and display a local image file a lot bigger than that (tested with a jpg of 6MB)
v = ui.ImageView() #pil_image = clipboard.get_image() #v.image = pil2ui(pil_image) v.image = ui.Image.named('P1020104.JPG') if keyboard.is_keyboard(): keyboard.set_view(v) else: v.present('sheet')
-
@cvp yes, So my first thought was whether this was a bug.😂
-
@mieq yes, you were right, I first thought it was a problem of small memory for keyboard script
-
im sure we have checked but has your device givin full acsess to pykeys?
-
after some testing i suspect its access settings. i was able to get image using clipboard and display on keyboard
using io to convert PIL img from clipboard.
#!python3 import keyboard import clipboard import ui import io def ConvertPIL(img): with io.BytesIO() as bIO: img.save(bIO, 'png') return ui.Image.from_data(bIO.getvalue()) if __name__ == '__main__': v = ui.ImageView() v.image= ConvertPIL(clipboard.get_image()) if keyboard.is_keyboard(): keyboard.set_view(v) else: v.present('sheet')
-
@stephen I had full access, device = iPad mini 4
-
@stephen same crash with your code and no fault log...
-
-
@cvp my first was probably small. i ran couple more and as i expected, 8k image (7680 × 4320) unknown filesize.. was too large for either PIL or ui. i have had this problem before.
with 4k (3840 x 2160) fileize 2.5MB. i know worked in PIL and ui, i usually deal with 4000x4000 up to 6000, 6000 for my game assets.
if there is an issue on your side with image being too large i would sugest using
resize
withANTI_ALIAS
to resize image while maintaining quality. i have noticed that combining this method withscene
power of rescaling you get really impressive quality after resizing.of course my scaling example wouldnt work in keyboard.. 6kx6k=88MB but i hope it helps in getting your image to display
def ConvertPIL(): with io.BytesIO() as bIO: with Image.open('6k png test.png') as img: console.show_image('6k png test.png') resized = img.resize((2000, 2000), 1) # 1 == Anti-Alias resized.show() resized.save(bIO, 'png') resized.close() return ui.Image.from_data(bIO.getvalue(), 2) # 2 == scaling for retina can be 3 on newer models or 1 for no retina scaling bIO.close()
-
im using iPad Air2 (i believe this is same as iPad 5) with Retina screen (2x scale)
-
@stephen said:
im sure we have checked but has your device givin full acsess to pykeys?
I had full acsess to pykeys,Crash anyway.works
when Copying pictures below 500 kb.Running on my iPhone XR.Does this mean that different devices are different? -
ive heard iPhoneX has had alot of issues since launch with multiple apps.. never looked into this though.
aside from that i did a little research and your phone has:
Liquid Retina HD display 6.1-inch (diagonal) all-screen LCD Multi-Touch display with IPS technology 1792-by-828-pixel resolution at 326 ppi 1400:1 contrast ratio (typical) True Tone display Wide color display (P3) Haptic Touch 625 nits max brightness (typical) Fingerprint-resistant oleophobic coating Support for display of multiple languages and characters simultaneously A12 Bionic chip Second-generation Neural Engine
my iPhone 6s has
IPS LCD capacitive touchscreen, 16M colors Size 4.7 inches, 60.9 cm2 (~65.6% screen-to-body ratio) Resolution 750 x 1334 pixels, 16:9 ratio (~326 ppi density) Protection Ion-strengthened glass, oleophobic coating 3D Touch PLATFORM OS iOS 9, upgradable to iOS 13.4 PowerVR GT7600 (six-core graphics)
So our devices are very close only reasonable diference would be screen size(not resolution) and CPU Generation.
that said following is my test with same code on my iPhone 6s.
Phone actually performed much faster than my iPad air2
im not sure what is creating this issue on your end .. could i posibly get a image you are using and the code? ad what format is the image ur trying to display? are cinverting the image from PIL (what
clipboard.get_image()
produces) to abmp
,png
,jpeg
ortiff
? (only formats i have used myself..)
i really want to help get you back on track. 🙃🤓 -
@stephen You are really nice,so much thanks.you can try this picture,
Just took with my phone. -
@mieq your picture of 720kb crash my iPad mini 4 and one picture of 600 kB works...
-
@cvp Me,too😆