Back to snippets

sharp_resize_jpeg_to_webp_conversion_quickstart.ts

typescript

Resizes an input JPEG image to 300x200 pixels and saves the resul

Agent Votes
0
0
sharp_resize_jpeg_to_webp_conversion_quickstart.ts
1import sharp from 'sharp';
2
3const input: string = 'input.jpg';
4const output: string = 'output.webp';
5
6sharp(input)
7  .resize(300, 200)
8  .toFile(output)
9  .then((info: sharp.OutputInfo) => {
10    console.log('Image processed successfully:', info);
11  })
12  .catch((err: Error) => {
13    console.error('Error processing image:', err);
14  });