How to convert the widget image to an image to use it in shortcuts

Hello everyone,

I want to convert the widget image that is drawn via context into a JPEG image. I want to use that image further in shortcuts to show a user how many times he has opened a particular app. Something like shown below. At this moment, I am just able to run the script in shortcut, and then I have to click on run manually every time. Please help. Other suggestions on how could i include the widget image into shortcuts is appreciated.

My code:

const width=125
const h=10
const w = new ListWidget()
w.backgroundColor=new Color("#222222")

// const now = new Date()
const weekday = args.shortcutParameter
getwidget(100, weekday, "Instagram Opened")
Script.setWidget(w)
Script.complete()
w.presentMedium()

function getwidget(total, haveGone, str) {
  const titlew = w.addText(str)
  titlew.textColor = new Color("#e587ce")
  titlew.font = Font.boldSystemFont(13)
  w.addSpacer(6)
  const imgw = w.addImage(creatProgress(total,haveGone))
  imgw.imageSize=new Size(width, h)
  w.addSpacer(6)
  
  
}



function creatProgress(total,havegone){
const context =new DrawContext()
context.size=new Size(width, h)
context.opaque=false
context.respectScreenScale=true
context.setFillColor(new Color("#48484b"))
const path = new Path()
path.addRoundedRect(new Rect(0, 0, width, h), 3, 2)
context.addPath(path)
context.fillPath()
if(weekday < 50){
context.setFillColor(new Color("#0aff53"))
}else{
context.setFillColor(new Color("#ff0a1a"))
}
const path1 = new Path()
path1.addRoundedRect(new Rect(0, 0, width*havegone/total, h), 3, 2)
context.addPath(path1)
context.fillPath()
return context.getImage()
var clipboardContents = 
Pasteboard.copyImage(context.getImage())

DocumentPicker.exportImage(context, name)

// console.log(`Clipboard contents: ${clipboardContents}`);

}