I’ve put together a list of the ones I find useful in my daily work as a web and software developer, from image manipulation, string validation, and PDF generation to minification, logging, and the creation of command-line applications.

1. Manipulate images

GraphicsMagick and ImageMagick are two popular tools for creating, editing, composing, and converting images. Thanks to the Node.js module gm you can use both tools directly from within your JavaScript code. The module supports all the typical image operations — resizing, clipping, and encoding to name just a few.

const gm = require('gm');
gm('/path/to/image.jpg')
  .resize(500, 250)
  .autoOrient()
  .write(response, error => {});

2. Process images

Sharp is based on the ultra-fast libvips image processing library, and claims to be four to five times faster than ImageMagick or GraphicsMagick when it comes to compressing and resizing images. It supports JPEG, PNG, WebP, TIFF, GIF and SVG images, and outputs data into either JPEG, PNG, WebP or uncompressed raw pixel streams.

3. Generate sprite sheets

Sprite sheets are bitmap files that contain many different small images (for example icons), and they are often used to reduce the overhead of downloading images and speed up the overall page load. Generating sprite sheets manually is very cumbersome, but with spritesmith you can automate the process. This module takes a folder as input and combines all the images in it into one sprite sheet. It also generates a JSON file that contains all the coordinates for each of the images in the resulting image, which you can directly copy in your CSS code.

#javascript #npm #coding #nodejs

Top 20 Node.js Modules You Need To Know
39.50 GEEK