Created
July 10, 2023 02:39
-
-
Save webarthur/02cca620a2a3f1d2e206966c1e9275f8 to your computer and use it in GitHub Desktop.
Sharp: Resize if image is bigger than a specific size (use withoutEnlargement prop)
This file contains 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
const sharp = require('sharp') | |
const maxWidth = 1200 | |
const maxHeight = 2000 | |
await sharp('uploads/image.png') | |
.resize(maxWidth, maxHeight * 1.5, { | |
fit: 'inside', | |
withoutEnlargement: true, // this | |
}) | |
.webp({ effort: 6 }) | |
.toFile('image.webp') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment