-
-
Save jerazo1223/5727aee2990f56ed148f6ee47fc5a193 to your computer and use it in GitHub Desktop.
Crop Imagenes
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
| export async function crop(done) { | |
| const inputFolder = 'src/img/gallery/full' | |
| const outputFolder = 'src/img/gallery/thumb'; | |
| const width = 250; | |
| const height = 180; | |
| if (!fs.existsSync(outputFolder)) { | |
| fs.mkdirSync(outputFolder, { recursive: true }) | |
| } | |
| const images = fs.readdirSync(inputFolder).filter(file => { | |
| return /\.(jpg)$/i.test(path.extname(file)); | |
| }); | |
| try { | |
| images.forEach(file => { | |
| const inputFile = path.join(inputFolder, file) | |
| const outputFile = path.join(outputFolder, file) | |
| sharp(inputFile) | |
| .resize(width, height, { | |
| position: 'centre' | |
| }) | |
| .toFile(outputFile) | |
| }); | |
| done() | |
| } catch (error) { | |
| console.log(error) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment