First of all, the dependencies are being called:
The sharp package it helps in the resizing images part;
The compress package compress automatically the image, however in the code, the compress function the compression code will fetch the resized image.
In the sharp (resize) function we need put as a parameter three things:
- path ~ Received file location
- outputPath ~ Where will the resized file go
- width ~ Width received by the user
When the sharp function are performed, the else conditional will call the compress function, like a callback.
Parameter to the compress_images function:
- pathInput ~ File that will be resized from the previous function
- outputPath ~ Where will the compress file go
In the compress function execution we put the outputPath of the resize function and the location where the file will be saved.
node app 'image file' 'px'