image processing in node js with sharp

Solutions on MaxInterview for image processing in node js with sharp by the best coders in the world

showing results for - "image processing in node js with sharp"
Elisa
10 Nov 2017
1/*
2    This code comes from Vincent Lab
3    And it has a video version linked here: https://www.youtube.com/watch?v=WtuJLcBvxI0
4*/
5
6// Import dependencies
7const sharp = require("sharp");
8const fs = require("fs");
9
10(async function () {
11
12    try {
13        // // png, webp, jpeg, tiff, heif, raw
14        // const info = await sharp("images/shapes.png").png().toFile("images/edited-shapes.png");
15        // const info = await sharp("images/shapes.png").jpeg().toFile("images/edited-shapes.jpeg");
16        // console.log(info);
17
18        // const image = await sharp("images/shapes.png").png().toBuffer();
19        // fs.writeFileSync("images/edited-shapes.png", image);
20
21        // // Metadata
22        // const metadata = await sharp("images/shapes.png").metadata();
23        // console.log(metadata);
24
25        // // Applies a grayscale effect to the image
26        // await sharp("images/shapes.png").grayscale().png().toFile("images/edited-shapes.png");
27
28        // // Resizes the image
29        // await sharp("images/shapes.png").resize(300, 200).png().toFile("images/edited-shapes.png");
30
31        // // Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
32        // await sharp("images/shapes.png").threshold(100).png().toFile("images/edited-shapes.png");
33
34        // // Recomb the image with the specified matrix.
35        // await sharp("images/shapes.png").recomb([
36        //     [0.3588, 0.7044, 0.1368],
37        //     [0.2990, 0.5870, 0.1140],
38        //     [0.2392, 0.4696, 0.0912],
39        // ]).png().toFile("images/edited-shapes.png");
40
41        // // Transforms the image using brightness, saturation and hue rotation.
42        // await sharp("images/shapes.png").modulate({
43        //     // brightness: 2, // Increase lightness by a factor of 2
44        //     // saturation: 0.5,
45        //     hue: 180 // Hue rotate by 180 degrees
46        // }).png().toFile("images/edited-shapes.png");
47
48        // // Blur the image. When used without parameters, performs a fast, mild blur of the output image. When a sigma is provided, performs a slower, more accurate Gaussian blur.
49        // // Value between 0.3 and 1000
50        // await sharp("images/shapes.png").blur().png().toFile("images/edited-shapes.png");
51
52        // Make a new image
53        const info = await sharp({
54            create: {
55                width: 1920,
56                height: 1080,
57                channels: 4,
58                background: { r: 255, g: 0, b: 0, alpha: 0.5 }
59            }
60        }).png().toFile("images/edited-shapes.png");
61    } catch (error) {
62        console.log(error);
63    }
64
65})();