I’m also trying to put an image in the background of a widget and I’m not succeeding either. I tried your script:
let fm = FileManager.iCloud()
let path = fm.documentsDirectory() + "/widget_background.jpg"
widget.backgroundImage = fm.readImage(path)
But the image is not displayed and here’s what the console returns to me:
2020-10-25 10:43:08: widget_background.jpg is stored in iCloud but the file have not been downloaded. Use downloadFileFromiCloud(filePath) on a FileManager to download the file before accessing it.
2020-10-25 10:43:08: /private/var/mobile/Library/Mobile Documents/iCloud~dk~simonbs~Scriptable/Documents/widget_background.jpg
This is done with the method FileManager.downloadFileFromiCloud(filepath) as described in the error message.
So the complete example would be
let fm = FileManager.iCloud();
let path = fm.documentsDirectory() + "/<your image name>.jpg";
// Image.fromFile(path) can also be used
w.backgroundImage = fm.readImage(path);
// "w" is your widget instance