Last active
March 18, 2024 12:09
-
-
Save JoepKockelkorn/07784995b0a7f5c31ebd23413ce4478b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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