I made a widget that downloads an image based on date and crops into the appropriate part, the image is small - 217 KB
https://root.breslan.co.uk/scratch/LP/210118.png
When I run the script in the app I get a lovely sharp image in my QuickLook.
http://root.breslan.co.uk/scratch/E0ADD14B-F0F0-4C95-B01B-13A26479493E.png
However in the widget it is very blurry…
Any idea how to improve the quality in the widget?
full code is below:
var d = getPreviousMonday()
var df = new DateFormatter()
df.dateFormat = "yyMMdd"
dateString = df.string(d)
let url = "https://root.breslan.co.uk/scratch/LP/" + dateString + ".png"
let req = new Request(url)
let originalImage = await req.loadImage()
var td = new Date()
td = td.getDay()
positionRow = [1,1,1,2,2,2,2]
positionColumn = [1,2,3,1,1,2,2]
let w = originalImage.size.width/3
let h = originalImage.size.height/2
yp = -(positionRow[td-1]-1)*h
xp = -(positionColumn[td-1]-1)*w
console.log("x:" + xp + " and y:" + yp)
dc = new DrawContext()
dc.opaque = true
dc.size = new Size(w,h)
dc.drawImageAtPoint(originalImage, new Point(xp,yp))
image = dc.getImage()
if (config.runsInWidget) {
// create and show widget
let widget = new ListWidget()
widget.backgroundImage = image
widget.setPadding(0, 0, 0, 0)
widget.url = url
Script.setWidget(widget)
Script.complete()
} else {
QuickLook.present(image)
}
function getPreviousMonday()
{
var date = new Date();
var day = date.getDay();
var prevMonday = new Date();
if(date.getDay() == 0){
prevMonday.setDate(date.getDate() - 7);
}
else{
prevMonday.setDate(date.getDate() - (day-1));
}
return prevMonday;
}