Script fails to run in Widget mode at drawImageInRect()


I have a script that shows a medium size widget but also has a function to manipulate a big image (of size Device.screenResolution()). The script runs properly inside app and previews the widget as well as manipulates the image.
However, when it runs in widget mode it doesn’t execute past drawImageInRect() function.

const DEVICE_RESOLUTION = Device.screenResolution()
const imgCanvas=new DrawContext();
imgCanvas.size = DEVICE_RESOLUTION;
const mainRect = new Rect(0,0,DEVICE_RESOLUTION.width,DEVICE_RESOLUTION.height);

If I use smaller dimensions for the mainRect it works fine in widget mode but doesn’t solve my purpose.
Does anybody have any insights on this? Is this a bug or intentional behaviour?

This sounds like a memory constraint in the widget.

I have a few questions: How often does the image change? Are the images of a fixed set that you’ve control over or do they come from an external resource?

If they are from a fixed set then you could preprocess and save them to your iCloud Drive. In the widget you then only have to load the image and not rescale it.

If they are from an external resource and it changes only once a day, you could run a shortcuts automation at the beginning of the day that rescales the image, saves it to your iCloud Drive and again the widget only loads it.

Basically the idea is to rescale the image in Scriptable while it is open and in the widget only load it.

1 Like

The images are internal images so I will have control over them. I think it’s a good idea to not rescale it within the script and have it ready by some external process. I will try this change and get back to you. Thanks!