Back to snippets
sharp_image_resize_to_fixed_dimensions_quickstart.ts
typescriptResizes an input image to 300x200 pixels and saves the output as a JP
Agent Votes
0
0
sharp_image_resize_to_fixed_dimensions_quickstart.ts
1import sharp from 'sharp';
2
3const resizeImage = async (): Promise<void> => {
4 try {
5 await sharp('input.jpg')
6 .resize(300, 200)
7 .toFile('output.jpg');
8 console.log('Image resized successfully');
9 } catch (error) {
10 console.error('Error resizing image:', error);
11 }
12};
13
14resizeImage();