Here's a script I talked about on @bdougie 's stream today. Someone in chat asked me to share, so I dug it up:
Install open-graph-image-grabber
// Menu: Open Graph Image Grabber// Description: Attempts to scrape the Open Graph image from the focused chrome tab// Author: John Lindquist// Twitter: @johnlindquist//📣 Note: Playwright takes ~20 seconds or so to install...let { getActiveTab } = await kit("chrome")let { attribute } = await kit("playwright")let { copyPathAsPicture } = await kit("file")let download = await npm("image-downloader")let sharp = await npm("sharp")let tab = await getActiveTab()console.log({ tab })setPlaceholder(`og:image of ${tab}`)let url = ""try {url = await attribute(tab,'head meta[property="og:image"]',"content")} catch (error) {setPlaceholder(`og:image not found. Checking twitter:image`)try {url = await attribute(tab,'head meta[name="twitter:image"]',"content")} catch (error) {console.log(error)setPlaceholder(`Sorry, giving up`)await wait(1000)exit()}}console.log({ url })setPlaceholder(`Found ${url}`)console.log({ url })let checkRedirects = await get(url)url = checkRedirects.request.res.responseUrlconsole.log({ redirectedUrl: url })let imageName = tab.split("/").pop()if (!imageName)imageName = tab.split("//").pop().replace("/", "")if (!imageName.endsWith(".png"))imageName = `${imageName}.png`console.log({ imageName })let dest = kenvPath("tmp", imageName)let { filename: image } = await download.image({url,dest,}).catch(error => {console.log(error)})console.log({ image })let width = parseInt(await arg("Enter width:"), 10)setPlaceholder(`Resizing to ${width}`)let metadata = await sharp(image).metadata()let newHeight = Math.floor(metadata.height * (width / metadata.width))let lastDot = /.(?!.*\.)/let resizedImageName = image.replace(lastDot, `-${width}.`)await sharp(image).resize(width, newHeight).toFile(resizedImageName)console.log({ resizedImageName })await copyPathAsPicture(resizedImageName)setPlaceholder(`Copied to clipboard`)await wait(500)