Automatic image resize for iOS widgets

Hello,
I need help to code an addition for the script. The image doesn’t fit in the widget - it is to big and parts of the image are missing. I need a way to automatically resize it for an medium widget. Has anyone an idea?
Thanks a lot.

const i = new Request(“https://www.donald.org/external/startbild.php”);
const clickUrl = “https://www.donald.org/external/startbild.php”;
const img = await i.loadImage();

let widget = createWidget(img, clickUrl)
if (config.runsInWidget) {
// create and show widget
Script.setWidget(widget)
Script.complete()
}
else {
widget.presentMedium()
}

function createWidget(img, widgeturl) {
let w = new ListWidget()
w.backgroundImage = img
w.url = widgeturl
return w
}

Instead of setting the image as a background, use w.addImage(img)

With a background, you can position other parts of the widget on top. Can you do that as well with an image added via w.addImage()?

Thank yo so much. It works.

const i = new Request(“https://www.donald.org/external/startbild.php”);
const clickUrl = “https://www.donald.org/external/startbild.php”;
const img = await i.loadImage();

let widget = createWidget(img, clickUrl)
if (config.runsInWidget) {
Script.setWidget(widget)
Script.complete()
}
else {
widget.presentLarge()
}

function createWidget(img, widgeturl) {
let w = new ListWidget()
let x = w.addImage(img)
x.centerAlignImage()
w.url = widgeturl
return w
}

Don’t think you can set other info on top of an email image with addImage.

AFAIK, You’d have to save a resized version of the image if you want to change the size on a background image.