GraphicsMagick for node
Instead of using this project, execute the gm or magick binaries using
cross-spawn directly.
Nearly 15 years ago I started this project as part of my start up which I sold later that year (2010). Having not used this project in over a decade and with no contributors for years, it's time to officially sunset gm.
No further Issues will be addressed. No Pull Requests will be merged. No new commits or npm releases will be made.
Massive thank you to everyone who contributed to this project over the years.
All past gm releases published to the npm registry will continue to be available for install. However, you should prioritize moving off of this project to an alternative because the risk of unpatched vulnerabilities in this project will continue to increase over time. No new commits will land and no new releases will be published.
The most obvious alternative to gm I see is installing cross-spawn and executing the GraphicsMagick or ImageMagick binaries directly, after all, that's pretty much all this project did. There may be other gm alternatives on npm but I don't what they are offhand so you'll need to search for something suitable yourself.
GraphicsMagick and ImageMagick for node
When reporting bugs please include the version of graphicsmagick/imagemagick you're using (gm -version/convert -version) as well as the version of this module and copies of any images you're having problems with.
First download and install GraphicsMagick or ImageMagick. In Mac OS X, you can simply use Homebrew and do:
brew install imagemagick
brew install graphicsmagick
then either use npm:
npm install gm
or clone the repo:
git clone git://github.com/aheckmann/gm.git
Subclass gm to enable ImageMagick 7+
const fs = require('fs')
const gm = require('gm').subClass({ imageMagick: '7+' });
Or, to enable ImageMagick legacy mode (for ImageMagick version < 7)
const fs = require('fs')
const gm = require('gm').subClass({ imageMagick: true });
Optionally specify the path to the executable.
const fs = require('fs')
const gm = require('gm').subClass({
appPath: String.raw`C:\Program Files\ImageMagick-7.1.0-Q16-HDRI\magick.exe`
});
…
…
// A buffer can be passed instead of a filepath as well
var buf = require('fs').readFileSync('/path/to/image.jpg');
gm(buf, 'image.jpg')
.noise('laplacian')
.write('/path/to/out.jpg', function (err) {
if (err) return handle(err);
console.log('Created an image from a Buffer!');
});
/*
A buffer can also be returned instead of a stream
The first argument to toBuffer is optional, it specifies the image format
*/
gm('img.jpg')
.resize(100, 100)
.toBuffer('PNG',function (err, buffer) {
if (err) return handle(err);
console.log('done!');
})
If gm does not supply you with a method you need or does not work as you'd like, you can simply use gm().in() or gm().out() to set your own arguments.
gm().command() - Custom command such as identify or convertgm().in() - Custom input argumentsgm().out() - Custom output argumentsThe command will be formatted in the following order:
command - ie convertin - the input argumentssource - stdin or an image fileout - the output argumentsoutput - stdout or the image file to write toFor example, suppose you want the following command:
gm "convert" "label:Offline" "PNG:-"
However, using gm().label() may not work as intended for you:
gm()
.label('Offline')
.stream();
would yield:
gm "convert" "-label" "\"Offline\"" "PNG:-"
Instead, you can use gm().out():
gm()
.out('label:Offline')
.stream();
which correctly yields:
gm "convert" "label:Offline" "PNG:-"
When identifying an image, you may want to use a custom formatting string instead of using -verbose, which is quite slow.
You can use your own formatting string when using gm().identify(format, callback).
For example,
gm('img.png').format(function (err, format) {
})
// is equivalent to
gm('img.png').identify('%m', function (err, format) {
})
since %m is the format option for getting the image file format.
Please document and refer to any platform or ImageMagick/GraphicsMagick issues/differences here.
Check out the examples directory to play around. Also take a look at the extending gm page to see how to customize gm to your own needs.
There are a few ways you can use the gm image constructor.
gm(path) When you pass a string as the first argument it is interpreted as the path to an image you intend to manipulate.gm(stream || buffer, [filename]) You may also pass a ReadableStream or Buffer as the first argument, with an optional file name for format inference.gm(width, height, [color]) When you pass two integer arguments, gm will create a new image on the fly with the provided dimensions and an optional background color. And you can still chain just like you do with pre-existing images too. See here for an example.The links below refer to an older version of gm but everything should still work, if anyone feels like updating them please make a PR
getters
manipulation
No open issues yet, or sync has not completed.