Skip to content

Instantly share code, notes, and snippets.

@JoepKockelkorn
Last active March 18, 2024 12:09
Show Gist options
  • Save JoepKockelkorn/07784995b0a7f5c31ebd23413ce4478b to your computer and use it in GitHub Desktop.
Save JoepKockelkorn/07784995b0a7f5c31ebd23413ce4478b to your computer and use it in GitHub Desktop.
import "@johnlindquist/kit"
// Menu: Resize an Image
// Description: Select an image in Finder. Type option + i to resize it.
// Shortcut:
let sharp = await npm("sharp")
let imagePath = await getSelectedFile()
let width = Number(await arg("Enter width:"))
let metadata = await sharp(imagePath).metadata()
let newHeight = Math.floor(
metadata.height * (width / metadata.width)
)
let lastDot = /.(?!.*\.)/
let resizedImageName = imagePath.replace(
lastDot,
`-${width}.`
)
await sharp(imagePath)
.resize(width, newHeight)
.toFile(resizedImageName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment