

Move into the newly created directory using the cd command:Ĭreate a package.json file using npm init command to keep track of the project dependencies: Open your terminal and create the directory for the project using the mkdir command:

Step 1 - Setting Up the Project Directory and Downloading Imagesīefore you start writing your code, you need to create the directory that will contain the code and the images you’ll use in this article.

Follow Understanding the Event Loop, Callbacks, Promises, and Async/Await in JavaScript to review asynchronous programming. You can follow How To Write and Run Your First Program in Node.js to learn the basics.īasic understanding of asynchronous programming in JavaScript. You can follow How to Install Node.js and Create a Local Development Environment to learn how to install Node.js and npm on your system.īasic knowledge of how to write, and run a Node.js program.

Node.js set up in your local development environment. By the end of this tutorial, you’ll have a good understanding of how to process images in Node.js. Finally, you will composite images, and add text on an image. You will then crop, grayscale, rotate, and blur an image. In this tutorial, you’ll use sharp to read an image and extract its metadata, resize, change an image format, and compress an image. sharp is a popular Node.js image processing library that supports various image file formats, such as JPEG, PNG, GIF, WebP, AVIF, SVG and TIFF. This article will focus on the sharp module. Node.js has an ecosystem of libraries you can use to process images, such as sharp, jimp, and gm module. With image processing, your application can resize and compress all the user-uploaded images, which can significantly improve your application performance and save your server disk space. This can negatively impact the application load speed, and also waste your server space. For example, if you’re writing a web application that allows users to upload images, users may upload unnecessary large images. It’s common for applications that handle user-uploaded content to process images. The process involves reading an image, applying methods to alter or enhance the image, and then saving the processed image. Introductionĭigital image processing is a method of using a computer to analyze and manipulate images. The author selected the Diversity in Tech Fund to receive a donation as part of the Write for DOnations program.
