sharp


1. Resize an Image:

const sharp = require('sharp');
sharp('input.jpg').resize(300, 200).toFile('output.jpg');

2. Crop an Image:

sharp('input.jpg').extract({ width: 200, height: 100, left: 100, top: 50 }).toFile('output.jpg');

3. Convert Image Format:

sharp('input.png').toFormat('jpeg').toFile('output.jpg');

4. Add Watermark to Image:

const composite = require('sharp-composite');
composite([
  sharp('input.jpg'),
  sharp('watermark.png').resize(100, 100)
]).blend('over').toFile('output.jpg');

5. Extract Image Metadata:

sharp('input.jpg').metadata().then(metadata => {
  console.log(metadata);
});

6. Create a Grayscale Image:

sharp('input.jpg').grayscale().toFile('output.jpg');

7. Convert Image to Base64:

8. Invert Image Colors:

9. Rotate Image:

10. Flip Image Horizontally/Vertically:

11. Resize and Pad Image:

12. Extract Image Frame:

13. Create a Thumbnail:

14. Resize Image with Aspect Ratio:

15. Blur Image:

16. Sharpen Image:

17. Add Text to Image:

18. Draw Shapes on Image:

19. Resize Image with Minimum Steps:

20. Resize Image with Percentage:

21. Convert Image to TIFF:

22. Create a Color Palette from Image:

23. Create a Histogram from Image:

24. Pipe Sharp Output to Another Process:

25. Batch Process Images: