imagemin-gm
GraphicsMagick plugin for imagemin
Install
$ npm install --save imagemin-gm
Important: This plugin requires GraphicsMagick to be installed.
On macOS for example, you can use Homebrew: brew install graphicsmagick
.
If this script throws the Exception Stream yields empty buffer
, this means the GraphicsMagick binaries can not be found in your path. You can pass the location to the ImageminGm
constructor.
Usage
const imagemin = require('imagemin')
const ImageminGm = require('imagemin-gm')
const imageminGm = new ImageminGm()
const plugins = [
imageminGm.resize({ width: 250, height: 250, gravity: 'Center' }),
imageminGm.convert('jpg')
]
imagemin(['images/*.gif'], 'output', { use: plugins })
.then(() => console.log('Images converted'))
.catch(err => console.error(err))
API
ImageminGm([gmPath])
Constructor, optionally pass the path to GraphicsMagick binaries (not the binary itself).
Example:
let imageminGm = new ImageminGm('/path/to/gm/binaries/')
let imageminGm = new ImageminGm('C:\\Path\\to\\gm\\binaries\\')
imageminGm.resize(options)
Resizes the image buffer. At least one dimension must be given, otherwise the image isn't altered. If both image dimensions are set, the image is resized to fit the constraints while maintaining the original aspect ratio. Image position can be adjusted with the gravity
option.
Options
width
height
gravity
(optional): NorthWest|North|NorthEast|West|Center|East|SouthWest|South|SouthEast
imageminGm.convert(format)
Converts the image buffer to a different image format (e.g. 'gif', 'jpeg', 'png').
Note: The original filename is used, although the image format has changed. You have to rename the file with the correct extension yourself afterwards.
License
MIT