Code Monkey home page Code Monkey logo

gm's Introduction

gm Build Status NPM Version

GraphicsMagick and ImageMagick for node

Bug Reports

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.

Getting started

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

Use ImageMagick instead of gm

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 });

Specify the executable path

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`
});

Basic Usage

var fs = require('fs')
  , 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');
});

// some files would not be resized appropriately
// http://stackoverflow.com/questions/5870466/imagemagick-incorrect-dimensions
// you have two options:
// use the '!' flag to ignore aspect ratio
gm('/path/to/my/img.jpg')
.resize(240, 240, '!')
.write('/path/to/resize.png', function (err) {
  if (!err) console.log('done');
});

// use the .resizeExact with only width and/or height arguments
gm('/path/to/my/img.jpg')
.resizeExact(240, 240)
.write('/path/to/resize.png', function (err) {
  if (!err) console.log('done');
});

// obtain the size of an image
gm('/path/to/my/img.jpg')
.size(function (err, size) {
  if (!err)
    console.log(size.width > size.height ? 'wider' : 'taller than you');
});

// output all available image properties
gm('/path/to/img.png')
.identify(function (err, data) {
  if (!err) console.log(data)
});

// pull out the first frame of an animated gif and save as png
gm('/path/to/animated.gif[0]')
.write('/path/to/firstframe.png', function (err) {
  if (err) console.log('aaw, shucks');
});

// auto-orient an image
gm('/path/to/img.jpg')
.autoOrient()
.write('/path/to/oriented.jpg', function (err) {
  if (err) ...
})

// crazytown
gm('/path/to/my/img.jpg')
.flip()
.magnify()
.rotate('green', 45)
.blur(7, 3)
.crop(300, 300, 150, 130)
.edge(3)
.write('/path/to/crazy.jpg', function (err) {
  if (!err) console.log('crazytown has arrived');
})

// annotate an image
gm('/path/to/my/img.jpg')
.stroke("#ffffff")
.drawCircle(10, 10, 20, 10)
.font("Helvetica.ttf", 12)
.drawText(30, 20, "GMagick!")
.write("/path/to/drawing.png", function (err) {
  if (!err) console.log('done');
});

// creating an image
gm(200, 400, "#ddff99f3")
.drawText(10, 50, "from scratch")
.write("/path/to/brandNewImg.jpg", function (err) {
  // ...
});

Streams

// passing a stream
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');
});


// passing a downloadable image by url

var request = require('request');
var url = "www.abc.com/pic.jpg"

gm(request(url))
.write('/path/to/reformat.png', function (err) {
  if (!err) console.log('done');
});


// can also stream output to a ReadableStream
// (can be piped to a local file or remote server)
gm('/path/to/my/img.jpg')
.resize('200', '200')
.stream(function (err, stdout, stderr) {
  var writeStream = fs.createWriteStream('/path/to/my/resized.jpg');
  stdout.pipe(writeStream);
});

// without a callback, .stream() returns a stream
// this is just a convenience wrapper for above.
var writeStream = fs.createWriteStream('/path/to/my/resized.jpg');
gm('/path/to/my/img.jpg')
.resize('200', '200')
.stream()
.pipe(writeStream);

// pass a format or filename to stream() and
// gm will provide image data in that format
gm('/path/to/my/img.jpg')
.stream('png', function (err, stdout, stderr) {
  var writeStream = fs.createWriteStream('/path/to/my/reformatted.png');
  stdout.pipe(writeStream);
});

// or without the callback
var writeStream = fs.createWriteStream('/path/to/my/reformatted.png');
gm('/path/to/my/img.jpg')
.stream('png')
.pipe(writeStream);

// combine the two for true streaming image processing
var readStream = fs.createReadStream('/path/to/my/img.jpg');
gm(readStream)
.resize('200', '200')
.stream(function (err, stdout, stderr) {
  var writeStream = fs.createWriteStream('/path/to/my/resized.jpg');
  stdout.pipe(writeStream);
});

// GOTCHA:
// when working with input streams and any 'identify'
// operation (size, format, etc), you must pass "{bufferStream: true}" if
// you also need to convert (write() or stream()) the image afterwards
// NOTE: this buffers the readStream in memory!
var readStream = fs.createReadStream('/path/to/my/img.jpg');
gm(readStream)
.size({bufferStream: true}, function(err, size) {
  this.resize(size.width / 2, size.height / 2)
  this.write('/path/to/resized.jpg', function (err) {
    if (!err) console.log('done');
  });
});

Buffers

// 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!');
})

Custom Arguments

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 convert
  • gm().in() - Custom input arguments
  • gm().out() - Custom output arguments

The command will be formatted in the following order:

  1. command - ie convert
  2. in - the input arguments
  3. source - stdin or an image file
  4. out - the output arguments
  5. output - stdout or the image file to write to

For 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:-"

Custom Identify Format String

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.

Platform differences

Please document and refer to any platform or ImageMagick/GraphicsMagick issues/differences here.

Examples:

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.

Constructor:

There are a few ways you can use the gm image constructor.

    1. gm(path) When you pass a string as the first argument it is interpreted as the path to an image you intend to manipulate.
    1. gm(stream || buffer, [filename]) You may also pass a ReadableStream or Buffer as the first argument, with an optional file name for format inference.
    1. 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

Methods

compare

Graphicsmagicks compare command is exposed through gm.compare(). This allows us to determine if two images can be considered "equal".

Currently gm.compare only accepts file paths.

gm.compare(path1, path2 [, options], callback)
gm.compare('/path/to/image1.jpg', '/path/to/another.png', function (err, isEqual, equality, raw, path1, path2) {
  if (err) return handle(err);

  // if the images were considered equal, `isEqual` will be true, otherwise, false.
  console.log('The images were equal: %s', isEqual);

  // to see the total equality returned by graphicsmagick we can inspect the `equality` argument.
  console.log('Actual equality: %d', equality);

  // inspect the raw output
  console.log(raw);

  // print file paths
  console.log(path1, path2);
})

You may wish to pass a custom tolerance threshold to increase or decrease the default level of 0.4.

gm.compare('/path/to/image1.jpg', '/path/to/another.png', 1.2, function (err, isEqual) {
  ...
})

To output a diff image, pass a configuration object to define the diff options and tolerance.

var options = {
  file: '/path/to/diff.png',
  highlightColor: 'yellow',
  tolerance: 0.02
}
gm.compare('/path/to/image1.jpg', '/path/to/another.png', options, function (err, isEqual, equality, raw) {
  ...
})

composite

GraphicsMagick supports compositing one image on top of another. This is exposed through gm.composite(). Its first argument is an image path with the changes to the base image, and an optional mask image.

Currently, gm.composite() only accepts file paths.

gm.composite(other [, mask])
gm('/path/to/image.jpg')
.composite('/path/to/second_image.jpg')
.geometry('+100+150')
.write('/path/to/composite.png', function(err) {
    if(!err) console.log("Written composite image.");
});

montage

GraphicsMagick supports montage for combining images side by side. This is exposed through gm.montage(). Its only argument is an image path with the changes to the base image.

Currently, gm.montage() only accepts file paths.

gm.montage(other)
gm('/path/to/image.jpg')
.montage('/path/to/second_image.jpg')
.geometry('+100+150')
.write('/path/to/montage.png', function(err) {
    if(!err) console.log("Written montage image.");
});

Contributors

https://github.com/aheckmann/gm/contributors

Inspiration

http://github.com/quiiver/magickal-node

Plugins

https://github.com/aheckmann/gm/wiki

Tests

npm test

To run a single test:

npm test -- alpha.js

License

(The MIT License)

Copyright (c) 2010 Aaron Heckmann

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

gm's People

Contributors

adurrive avatar agokhale avatar aheckmann avatar akreitals avatar alcidesv avatar danez avatar danmilon avatar desigens avatar drochag avatar emaniacs avatar emohacker avatar encima avatar fdecampredon avatar freshxopensource avatar jdiez17 avatar jonathanong avatar kainosnoema avatar kof avatar lbeschastny avatar longlho avatar luccastera avatar patrykmiszczak avatar pem-- avatar preynal avatar pwlmaciejewski avatar rodrigoalviani avatar rwky avatar ryanwholey avatar syzer avatar thomaschaaf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gm's Issues

raw image data serialization

Hello-

This is not really an issue but more of a question. Is there a feasible way to store/retrieve the image data from/to memory instead of hitting the filesystem? It seems like this was possible in PHP but I don't remember for sure.

Thanks,
Matt

Read from buffer

Would it be possible to add buffer as one of the options for gm? Reason I ask is because I'm reading a stream for a base64 encoded image and I create a new buffer from it, but since gm only accepts a string I have to write it to file first and then read the file instead of being able to go straight to gm with the buffer.

Thanks! ^^

gm identify: Unable to open file (/tmp/gmtDcxxb) [No such file or directory].

I'm using gm to downsample and crop images and am seeing this error fairly regularly, about 1% of requests. Making the same call a second time works just fine so it doesn't appear to be a problem with the inputs.

I realize it's internal to graphicsmagick but was hoping you might have some insight into what might be causing the issue and ways to alleviate the problem.

Can I get image blob?

Hello. Can I somehow get image blob after transformations without writing to filesystem? (I see write method all the time that writes to filesystem, but couldn't find method for getting image blob)

-flatten

I'm trying to run a command equivalent to:

convert Foo.psd -flatten Foo.jpg

Is there any way as of right now to get this -flatten working? If not, where can I start poking around to add it?

Animated Gifs break 'identify'?

Hi,

I saved this file to my hard drive: http://www.prguitarman.com/comics/poptart1red1.gif
When I run this code:

gm(tmp_path).identify(function(err, data){
                console.log(data);
});

I get this error?

[TypeError: Cannot set property 'Image' of undefined]
TypeError: Cannot set property 'Image' of undefined
    at ChildProcess.<anonymous> (/home/user/abc/src/node_modules/gm/lib/getters.js:121:18)
    at ChildProcess.<anonymous> (/home/user/abc/src/node_modules/gm/lib/command.js:208:18)
    at ChildProcess.emit (events.js:70:17)
    at maybeExit (child_process.js:361:16)
    at Process.onexit (child_process.js:397:5)

I just want to determine if a file is animated gif or not, I don't necessarily need to perform any operations on that image.

thanks!

Reserved word

Hi

I have got this error on [email protected]:

    ./node_modules/gm/index.js:59
    var super = gm;

    SyntaxError: <unknown message reserved_word>

Node version 0.6.7

crop.resize on JPEG

Doing crop then resize on a JPEG image (PNG seems ok) results in:```
Command failed: gm convert: geometry does not contain image (unable to crop image).


Removing ```
in("-size",  w +"x"+ h)

in lib/args.js:13 solves the issue, however I'm not sure about the deeper consequences.

Frames support

Support for frame manipulation with animated GIF files.

Ability to remove frames, add frames, etc.

Ability to detect number of frames.

Ability to detect number of used pixels and pixel colors on a frame.

Graceful failure when graphicsmagick is not available

Currently gm.stream will hang and the following error is reported:

  Error: write EPIPE
     at errnoException (net.js:646:11)
     at Object.afterWrite [as oncomplete] (net.js:480:18)

It would be nice if the error is detected and an informative error returned to any callbacks.

Error message if GraphicMagick is not installed

Hi,

I think the gm module should throw an error if graphicmagick is not installed on the system. It should atleast say that "Install graphicmagick or switch to Imagemagick".

Right now it just throws a cryptic error with a error code which on Googling translates into "Command not found".

Thanks

ERROR: spawn EMFILE (80 file limit?)

Error: spawn EMFILE
at errnoException (child_process.js:481:11)
at ChildProcess.spawn (child_process.js:444:11)
at child_process.js:342:9
at gm._spawn (/Users/myusername/node_modules/gm/lib/command.js:156:16)
at gm._exec (/Users/myusername/node_modules/gm/lib/command.js:137:17)
at gm.identify (/Users/myusername/node_modules/gm/lib/getters.js:74:10)
at gm.size (/Users/myusername/node_modules/gm/lib/getters.js:33:12)

.. attempted to walk a directory, getting image sizes for each image encountered.

Node: 0.6.12
OS: mac osx 10.6.8

I tried directly calling gm(<filename>).size(function(e, v){ ... }); on the last file in the list before the error, and it worked fine.

I created an array literal containing the 81 image filenames logged to the console leading up to the error and iterating over just them. Same result. But as soon as I removed any one of them from the array, everything was ok.

getterIdentify.js test fails

The getterIdentify.js test is failing for me on line 15 due to what is perhaps a floating point rounding difference. Here is the output:


Jubilee:gm[master]$ make test
The "sys" module is now called "util". It should have a similar interface.

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
AssertionError: "71.71 (0.2812)" == "71.70 (0.2812)"
    at gm.<anonymous> (/Users/joshua/Working/libraries/gm/test/getterIdentify.js:15:12)
    at ChildProcess.<anonymous> (/Users/joshua/Working/libraries/gm/lib/getters.js:142:23)
    at ChildProcess.<anonymous> (/Users/joshua/Working/libraries/gm/lib/command.js:207:18)
    at ChildProcess.emit (events.js:70:17)
    at maybeExit (child_process.js:360:16)
    at Socket.<anonymous> (child_process.js:457:7)
    at Socket.emit (events.js:67:17)
    at Array.16 (net.js:335:10)
    at EventEmitter._tickCallback (node.js:192:40)
make: *** [test] Error 1


This is on Node v0.6.14. Is anyone else having issues like this with the test suite? 

Unexpected size as result when having multicalls on the same file

I am not sure what happens here but really weird.

Node v0.8.2 on Mac (unfortunately can not determine if I run GraphicsMagick or ImageMagick)

Code

var gm = require('gm');
gm( __dirname + '/data/img/icons/favicon.png').size(function(err, size) {
console.log(size);
});

gm( __dirname + '/data/img/icons/favicon.png').size(function(err, size) {
console.log(size);
});

gm( __dirname + '/data/img/loading.gif').size(function(err, size) {
console.log(size);
});

gm( __dirname + '/data/img/loading.gif').size(function(err, size) {
console.log(size);
});

Images can be found here

https://github.com/vanng822/jcash/blob/master/tests/data/img/icons/favicon.png
https://github.com/vanng822/jcash/blob/master/tests/data/img/loading.gif

Output

-----node test.js, good output
{ width: 16, height: 16 }
{ width: 16, height: 16 }
{ width: 35, height: 35 }
{ width: 35, height: 35 }
-----node test.js
{ width: 16, height: 16 }
undefined
{ width: 35, height: 35 }
{ width: 35, height: 35 }
------ node test.js
{ width: 16, height: 16 }
undefined
{ width: 35, height: 35 }
{ width: 35, height: 35 }
------node test.js
{ width: 16, height: 16 }
undefined
{ width: 35, height: 35 }
{ width: 1, height: 1 }

Can't parse EXIF data using ImageMagick

When using ImageMagick, the identify method doesn't output correct EXIF data.

The problem is with the regex, because ImageMagick returns the EXIF data in this format:

exif:Model: Canon

You only end up with a "exif" property after executing identify.

streamed content-length?

Hey, I've been using GM for some time and am quite happy with how it makes my life easier :)
I've been trying to wrap my head around a new approach I'm trying and wondering why it isn't working as expected.
I'm using following code and want to push the stream to my amazon s3 bucket with aws2js module;

var readStream = fs.createReadStream('/path/to/my/img.png');
gm(readStream, 'img.png')
.stream(function (err, stdout, stderr) {
    s3.putStream(path, stdout, 'public-read', {'content-type': 'image/png', 'content-length': ?????}, function (err, result) {
    ....
    });
});

everything works fine with aws2js and streams, IF I know the content-length (when I just directly store the picture without resize). But when I don't specify the content-length, it doesnt work and my file ends up beeing 0bytes in size.
Since I'll be wanting to resize the picture and then send it to my bucket, I'll need to know how big the resized img will be.

Is there a way, how I can retrieve that information?

Thank you for your help in kicking me in the right direction :)

Performing a large number of operations

I am using gm to create large images with many small items drawn on them (a map in a computer game). The problem is that beyond a certain number of operations I start to receive the error "Command failed: execvp(): Argument list too long". This can be reproduced with the following code:

var Gm = require('gm');
var image = Gm(100, 100, '#FFF');
for (var i = 0; i < 10000; i++) {
image.drawCircle(0,0,5,5);
}
image.write('test.gif', function(e) {
if (e) {
console.log('Error:');
console.log(e);
}
else {
console.log('Done.');
}
});

I am able to circumvent this issue by writing to file every few iterations, but this seems hacky because I never really know how much more 'argument room' is available and the constant writes really slows things down.

Error running with nodejs w32 binaries

Hi,i run nodejs win32 binaries and get this error with gm :
{"0":
...
type:undefined,
message:"Command failed: execvp(): No such file of directory\n",
killed:false,
code:127,
...
"1" : "",
"2" : "execvp(): No such file or directory\n",
"3": "gm convert -size 420x220 ....

How can fix that.
Thanks

Animated GIFs return 'identify' data for last frame

The parser for the identify output in getters.js gathers all the key=value pairs after the Image: header, but does not handle gathering the output for multiple images.

I've patched on my branch to make this return the output from the first image, because the first image in the series contains the correct canvas size.

I can either issue a pull request for this work-around, or I can make the parser gather the output for multiple images, or something else.

thoughts?

IPTC data in identify

Hey,

graphicsmagik returns IPTC data such as caption, GPS etc on the command line

gm identify -ping -verbose image.jpg

However the node gm identify wrapper only returns a subset of this data, even thought it uses the same command as above.

I believe only few changes will be needed to the parser that transforms stdout to JSON.

some helpfull methods are missing

Could you add some helpfull methods for graphicsMagicks and ImageMagicks such as "setInterlaceScheme", "stripImage", "compositeImage", and "clone"?

Document how run tests so new contributors can more easily contribute

As a new contributor, I couldn't figure out how to run the tests:

npm test

or

make test

failed. I'm not sure if it's because the tests themselves are not passing or if there is an extra step needed to get the test suite running that I did not complete. It would be nice to document that on the README so that new contributors can run the test suite.

why got the error:'command failed'

I install gm on windows with npm.
When I run the 'thumb' example,I got the 'Error: Command failed: CreateProcessW: xxxxx' and 'code: 127, signal: null'
Dose gm support in windows?

Tests Fail

I am trying to get the tests to pass so that I have a good starting point but I am running into problems. Bellow is the output from the tests. How can I figure out what tests are failing?

$ node test/index.js
√√√√√√√√√√√√√√√√√√√√√√√√√√√√√√√√√√√░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Error: Command failed: execvp failed, errno = 2 (No such file or directory)
gm convert: "gs" "-q" "-dBATCH" "-dMaxBitmap=50000000" "-dNOPAUSE" "-sDEVICE=ppmraw" "-dTextAlphaBits=4" "-dGraphicsAlphaBits=4" "-r72x72" "-g680x136" "-sOutputFile=/var/folders/dm/y_gb705d3kz_x0rkrd7t36zw0000gn/T/gmPdl5eB" "--" "/var/folders/dm/y_gb705d3kz_x0rkrd7t36zw0000gn/T/gmV58OUO" "-c" "quit".
execvp failed, errno = 2 (No such file or directory)
gm convert: "gs" "-q" "-dBATCH" "-dMaxBitmap=50000000" "-dNOPAUSE" "-sDEVICE=ppmraw" "-dTextAlphaBits=4" "-dGraphicsAlphaBits=4" "-r72x72" "-g680x136" "-sOutputFile=/var/folders/dm/y_gb705d3kz_x0rkrd7t36zw0000gn/T/gmPdl5eB" "--" "/var/folders/dm/y_gb705d3kz_x0rkrd7t36zw0000gn/T/gmV58OUO" "-c" "quit".
gm convert: Postscript delegate failed (/var/folders/dm/y_gb705d3kz_x0rkrd7t36zw0000gn/T/gmIigJjO).
execvp failed, errno = 2 (No such file or directory)
gm convert: "gs" "-q" "-dBATCH" "-dMaxBitmap=50000000" "-dNOPAUSE" "-sDEVICE=ppmraw" "-dTextAlphaBits=4" "-dGraphicsAlphaBits

gm delegates missing

When I installed gm with prefix I got this error

Command failed: gm identify: Unable to access configuration file (delegates.mgk) [No such file or directory].

Installing it without a prefix fixed that error but I now get errors like this when I try to open an image

code

gm(files.file.path).size(function (err, size) {
    console.log(err);
    console.log(size);
});

error

Command failed: gm identify: No decode delegate for this image format (/tmp/8c058c811a50b6441e98723c777b3199.JPG).

Error using .minify()

Error: Command failed: gm convert: Unable to open file (1) [No such file or directory].

It looks like the factor is getting passed in as a filename or something.

Resize options?

Thanks for the convenience library, works great. The only thing I'd wish for is a bit more flexibility regarding the resize options.

http://www.graphicsmagick.org/GraphicsMagick.html#details-geometry

To get the most out of it I think the function could be redefined something like:

// http://www.graphicsmagick.org/GraphicsMagick.html#details-resize
//valid arguments : width, height, options

proto.resize = function resize(args) {
var size;
size = "";
if (args.width != null) {
size += args.width;
}
size += "x";
if (args.height != null) {
size += args.height;
}
resize = size;
if (args.options != null) {
resize += args.options;
}
return this["in"]("-size", size).out("-resize", resize);
};

Support for mogrify?

I'm trying to scale an image in place. Is there any way to do something equivalent to:

gm mogrify -size 120x120 my-image.jpg -resize 120x120

npm warning

Seeing this warning when I run "npm install" with gm >= 1.1.0 in my app's package.json. Did the format of the bugs section of package.json change?

Does not play well with streams paused by connect

If I have a stream that is paused, pass it to gm, then resume it, stream gives an error:

var gm = require("gm");
var fs = require("fs");
var pause = require("connect").utils.pause;

var source = fs.createReadStream("img.png");
var pauser = pause(source);

setTimeout(function () {
    gm(source, "img.png")
        .resize(200, 200)
        .stream("png", function (err, stdout, stderr) {
            if (err) {
                console.log("err", err);
                process.exit(1);
            } else {
                stdout.pipe(process.stdout);
                stderr.pipe(process.stderr);
            }
        });

    pauser.resume();
}, 100);
$ node test.js
err [Error: gm().stream() or gm().write() with a non-readable stream. Pass "{bufferStream: true}" to identify() or getter (size, format, etc...)]

The problem is that the stream does indeed have readable: false since it's already emitted all its events, which are caught by connect and stored in the _events property to be re-emitted later, when I call pauser.resume().

So I guess it's partially connect's fault, since usually you can assume that non-readable streams will not emit any more events. But, a solution is kind of necessary, since there's otherwise no way to defer streaming image processing until after an asynchronous event (e.g. user authorization) has occurred. Note that the native stream's pause method does not work on HTTP streams; data events get dropped, necessitating something like connect's custom pause function.

Not sure what a good solution is here. For now I've hacked around it by inserting source.readable = true before calling gm.

/cc @visionmedia for any connect-related advice, @isaacs since this is an interesting case of "unfuck HTTP"

Error: CreateProcessW: The system cannot find the file specified. on Windows 7

Hi,

I tried to resize image with gm but I got this error

[2012-06-05 03:02:58.648] [INFO] console - Error: Command failed: CreateProcessW: The system cannot find the file specified.

at ChildProcess.<anonymous> (C:\Users\user00492\workspace\inbrush\node_modules\gm\lib\command.js:203:17)
at ChildProcess.emit (events.js:70:17)
at maybeExit (child_process.js:362:16)
at Socket.<anonymous> (child_process.js:467:7)
at Socket.emit (events.js:67:17)
at Array.1 (net.js:335:10)
at EventEmitter._tickCallback (node.js:192:40)

I am using node v0.6.17 on windows 7, and this is my code

var gm = require('gm');
gm('C:/Users/user00492/default.jpg')
.resize(40, 40)
.noProfile()
.write(
'C:/Users/user00492/resized.jpg', function(err) {
if (!err)
console.log('done');
else
console.log(err)
});

Could anyone help me to fix this problem?

Thanks.

PNG module for GM

Hi I've installed gm on server, with gif images it works fine, but when I use png image the error are thrown - "Command failed: gm identify: No decode delegate for this image format (/tmp/logo.png)". I've installed libpng and zlib but still have this error, what must I do to make it works???

Composite?

Can composite be added please? I need to composite one image on top of another at a specific location. I cannot figure out what to do from the source (looking at morph example).

Please advise. Thanks!

Edit: Also, the source image needs to be cropped and resized. Should this be done with 2 steps or can this be passed as args to the composite command?

Non-conforming primitive error on drawPolygon

Occurs for me whenever I draw any polygon, polyline, or bezier. These functions worked for me in previous versions.

If you look at those three methods in drawing.js it looks like the draw method is being passed an array of arguments rather than having the array of arguments .applied to it.

I fixed this for myself by changing:

return this.draw(["polyline"].concat(formatPoints(arguments)));

to

return this.draw.apply(this, ["polyline"].concat(formatPoints(arguments)));

for all three functions.

Not working with imagemagick?

Hello,

Just to point out that I first try the module and had the following error:

Error: Command failed: execvp(): No such file or directory

Since I only had imagemagick installed, I tried installing graphicsmagick and everything ran smoothly.

Cheers

tests randomly fail

not sure which test yet. after resolving this we can tag/release

stream.js:74
    dest.end();
         ^
TypeError: Object [object Object] has no method 'end'
    at Socket.onend (stream.js:74:10)
    at Socket.emit (events.js:81:20)
    at Socket._onReadable (net.js:652:51)
    at IOWatcher.onReadable [as callback] (net.js:177:10)
make: *** [test] Error 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.