hmvorti.blogg.se

Nodejs image resize
Nodejs image resize








Here I showed only two functions - resize and toFile. You can any approach either callback or promise.

#NODEJS IMAGE RESIZE INSTALL#

Install the sharp library of NodeJS using the below command inside your NodeJS project. In this tutorial, we are going to use the NodeJS Sharp Library for doing the image resize activity. Once the user uploads an image to Facebook, they will automatically convert your images to various dimensions based on their optimization concept.

nodejs image resize

If you take Facebook, It is using various image sizes to give the user a better user experience.

nodejs image resize

To solve this problem, we as a web developer, we always will do the image resize activity automatically when the image is uploaded to the server. So it will be a big problem for users to load the image fully. But not all people had the same better connectivity. Today we have better internet connectivity. However, it will need 15MB bandwidth each time to show the image to the users. Say, for example, Assume if you are taking a photo from a professional camera and the file size around 15MB.

  • Create Different dimensions of the same image with low size( Profile Icon, Thumbnail size, Card Post Size, Cover Image Size, etc).
  • Reduce large file size to optimal size( 15MB to 800KB without losing the quality).
  • So we need to do two things on the image uploaded by the user. However, we can not keep a large file of the original image due to the growing usage of images. The server stores the high-resolution images(original image uploaded by the customer). We uploading the images to the cloud server or we are sharing the images with our known people through social media or other communication tools.

    nodejs image resize

    A normal camera image occupies a minimum of 2MB of memory. Due to the advanced devices, always the size of the image is also high. Everyone has a high-resolution mobile phone or professional camera. Today we have more sophisticated devices to capture the image.








    Nodejs image resize