📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP

gm

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gm

GraphicsMagick and ImageMagick for node.js

1.25.1
latest
Version published
Weekly downloads
420K
-8.55%
Maintainers
0
Weekly downloads
 
Created

What is gm?

The gm (GraphicsMagick) npm package is a Node.js wrapper for the GraphicsMagick and ImageMagick image processing libraries. It allows you to perform a wide range of image manipulation tasks such as resizing, cropping, rotating, and adding text to images.

What are gm's main functionalities?

Image Resizing

This feature allows you to resize an image to the specified dimensions. In this example, the image is resized to 240x240 pixels.

const gm = require('gm');
gm('/path/to/image.jpg')
  .resize(240, 240)
  .write('/path/to/resized_image.jpg', function (err) {
    if (!err) console.log('Image resized successfully');
  });

Image Cropping

This feature allows you to crop an image to the specified width and height, starting from the specified x and y coordinates. In this example, a 100x100 pixel area is cropped from the image starting at coordinates (50, 50).

const gm = require('gm');
gm('/path/to/image.jpg')
  .crop(100, 100, 50, 50)
  .write('/path/to/cropped_image.jpg', function (err) {
    if (!err) console.log('Image cropped successfully');
  });

Image Rotation

This feature allows you to rotate an image by a specified angle. In this example, the image is rotated by 45 degrees with a green background fill.

const gm = require('gm');
gm('/path/to/image.jpg')
  .rotate('green', 45)
  .write('/path/to/rotated_image.jpg', function (err) {
    if (!err) console.log('Image rotated successfully');
  });

Adding Text to Image

This feature allows you to add text to an image. In this example, the text 'Hello World' is added to the image at coordinates (30, 50) with a font size of 68.

const gm = require('gm');
gm('/path/to/image.jpg')
  .fontSize(68)
  .drawText(30, 50, 'Hello World')
  .write('/path/to/text_image.jpg', function (err) {
    if (!err) console.log('Text added to image successfully');
  });

Other packages similar to gm

FAQs

Package last updated on 25 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts