gm
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
array-parallel | 0.1.3 | 2.45 kB | MIT | prod | |
array-series | 0.1.5 | 2.43 kB | MIT | prod | |
cross-spawn | 4.0.2 | 4.99 kB | MIT | prod | |
debug | 3.2.7 | 16.48 kB | MIT | prod |
gm
is a package available on NPM, primarily designed to provide Node.js bindings for ImageMagick and GraphicsMagick. Graphicsmagick and ImageMagick are recognized tools in image processing, both of which allow for complex manipulation, conversion and analysis of images in various formats. The package empowers developers with the ability to perform wide range of image operations such as resizing, cropping, annotating images among many others, right within their Node.js applications.
To use gm, first, you need to download and install either GraphicsMagick or ImageMagick. After successful installation of either ImageMagick or GraphicsMagick, you can then proceed to install gm using npm:
npm install gm
Next, you can start using the gm package in your JavaScript code as illustrated:
const gm = require('gm');
//resize and remove EXIF profile data
gm('/path/to/my/img.jpg')
.resize(240, 240)
.noProfile()
.write('/path/to/resize.png', function (err) {
if (!err) console.log('done');
});
//note replace '/path/to/my/img.jpg' with the path to the image
//you want to process and '/path/to/resize.png' with the path
//to where you want to save the processed image
In addition to basic usage, gm also supports stream operations:
var readStream = fs.createReadStream('/path/to/my/img.jpg');
gm(readStream, 'img.jpg')
.write('/path/to/reformat.png', function (err) {
if (!err) console.log('done');
});
You can refer to the examples given in the readme for more usage scenarios involving gm.
The official gm documentation is available here. This documentation provides a comprehensive guide on the usage of the package β from the basic setup to utilizing advanced features. The documentation is well-structured, offering an exhaustive list of features which the library supports, and the corresponding methods to utilize these features. The gm Github repository is also an invaluable resource with several examples and further usage explanations.