错误:在节点中使用GM时产生ENOENT

时间:2021-09-25 15:27:54

When I try to resize an image like this:

当我试图调整一个像这样的图像大小时:

                gm('public/uploads/1710410635.jpg')
                .resize(240, 240)
                .noProfile()
                .write('public/uploads/1710410635_t.jpg', function (err) {
                  if (!err) console.log('done');
                });

I get this error:

我得到这个错误:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:945:11)
    at Process.ChildProcess._handle.onexit (child_process.js:736:34)

My file structure is as follows:

我的文件结构如下:

错误:在节点中使用GM时产生ENOENT

The code is executed in the postnewsitem.js file

代码在postnewsitem中执行。js文件

why is this error occurring & how do I solve it ?

为什么会出现这种错误?我该如何解决?

edit: GraphicsMagick works, proof:

编辑:GraphicsMagick作品,证明:

错误:在节点中使用GM时产生ENOENT

9 个解决方案

#1


64  

Install ImageMagick and use subClass imageMagick.

安装ImageMagick并使用子类ImageMagick。

  1. Install ImageMagick

    安装ImageMagick

    sudo apt-get install imagemagick
    
  2. using subClass imagemagick:

    使用imagemagick子类:

    var gm = require('gm').subClass({ imageMagick: true });
    

#2


11  

I'm running nodejs on windows 7 with installed gm and imagemagick and seems that there was conflict between both modules so i googled a bit and found out how to avoit that. I added this line and that solved my ENOENT problem: var imageMagick = gm.subClass({ imageMagick: true }); so the code now looks like this:

我在windows 7上运行nodejs,安装了gm和imagemagick,两个模块之间似乎有冲突,所以我在谷歌上搜索了一下,找到了如何实现这一点。我添加了这一行,这就解决了我的ENOENT问题:var imageMagick = gm.subClass({imageMagick: true});代码是这样的

var gm = require('gm'); 
var imageMagick = gm.subClass({ imageMagick: true });

imageMagick('test/pig.jpg').rotate('green', 45).write('test/crazy_pig.jpg', function (err) {
    if (!err) console.log('crazy pig has arrived');
    else console.log(err);
})

OR you can do that when requiring gm, like so:

或者当需要gm时,你也可以这样做,比如:

var gm = require('gm').subClass({ imageMagick: true });

#3


4  

Had the same problem with Node.js application running on Windows using IIS. Problem has gone when I set "Load User Profile" option in "Advanced settings" of appropriate AppPool to "True"

Node也有同样的问题。使用IIS在Windows上运行的js应用程序。当我在适当的AppPool的“高级设置”中设置“Load User Profile”选项为“True”时,问题就消失了

#4


2  

I faced the same problem and solved it in the given way.

我遇到了同样的问题,并以既定的方式解决了它。

var gm = require('gm'); 

gm('public/uploads/1710410635.jpg').options({imageMagick: true}).resize(240,240).write('public/uploads/1710410635.jpg', function (err) {
if (!err) console.log('Done');
else console.log(err);
})

Note: If you haven't installed imageMagick. Please install that first

注意:如果您没有安装imageMagick。请先安装

#5


1  

Another scenario where this might happen (when using windows) is if you try to run your code from a UNC Path. mapping a drive letter and running over the mapped drive letter solves this problem as well.

另一个可能发生这种情况的场景(当你使用windows时)是如果你试图从UNC路径运行你的代码。映射驱动器号和在映射的驱动器号上运行也解决了这个问题。

#6


1  

I have the same issue as you and this was SOLUTION. ImageMagick was working correctly in terminal/console but not in nodejs (gm module). After 2 days of losing hair i fixed it by adding PATH variable to environment variables process.env.PATH There should be path to your imagemagick and other executables. Node.js has some PATH from system but for some reasone GM is ignoring it and using process.env.PATH

我和你有同样的问题,这就是解决方案。ImageMagick在终端/控制台运行正常,但在nodejs (gm模块)中没有。在丢失头发2天后,我将路径变量添加到环境变量process.env中。路径应该有指向imagemagick和其他可执行文件的路径。节点。js有一些来自系统的路径,但是由于某些原因,GM忽略了它并使用process.env.PATH

I created environment variable PATH(process.env.PATH) and set value to bin:node_modules/.bin:/usr/local/bin:/usr/bin:/bin I'm using MAC OS X

我创建了环境变量PATH(process.env.PATH),并将值设置为bin:node_modules/。bin:/usr/local/bin:/usr/bin:/bin:/bin:我在用MAC OS X

I got imageMagick installed with brew (brew install imagemagick)

我用brew安装了imageMagick (brew install imageMagick)

#7


0  

Because I found this problem many times here on *, I want to share this answer: https://*.com/a/25461564/3970623

因为我在*上多次发现了这个问题,所以我想分享这个答案:https://*.com/a/25461564/3970623

The "spawn ENOENT" seems to be caused by a valid unix tools installation which is accessible using PATH environment variable.

“spawn ENOENT”似乎是由一个有效的unix工具安装引起的,该安装可以使用PATH环境变量进行访问。

#8


0  

In my case it was very simple. It ocurred rigth after instalation of GraphicsMagick in windows 10: I tryed using a console that was yet open before installing GraphicsMagick. Therefore it used old path information and didn´t found GraphicsMagick. Solution: I had to open a new console for running the node for using gm.

就我而言,这很简单。在windows 10中安装了GraphicsMagick之后,它变得更加精确了:我试着在安装GraphicsMagick之前使用一个尚未打开的控制台。因此,使用旧的路径信息,并´t GraphicsMagick找到。解决方案:我必须为使用gm运行节点打开一个新的控制台。

#9


0  

/gm/lib/command.js have an option where you can set the appPath, if gm is already working through the terminal, you can get the path to gm and pass it via the subClass function,In my case gm was installed in /usr/local/bin/ using brew on MacOsx.

通用汽车/ lib /命令。js有一个选项,可以设置appPath,如果gm已经通过终端工作,您可以获取到gm的路径并通过子类函数传递它,在我的例子中,gm是在/usr/local/bin/中安装的,使用的是MacOsx上的brew。

var gm = require('gm').subClass({ appPath: "/usr/local/bin/" });

#1


64  

Install ImageMagick and use subClass imageMagick.

安装ImageMagick并使用子类ImageMagick。

  1. Install ImageMagick

    安装ImageMagick

    sudo apt-get install imagemagick
    
  2. using subClass imagemagick:

    使用imagemagick子类:

    var gm = require('gm').subClass({ imageMagick: true });
    

#2


11  

I'm running nodejs on windows 7 with installed gm and imagemagick and seems that there was conflict between both modules so i googled a bit and found out how to avoit that. I added this line and that solved my ENOENT problem: var imageMagick = gm.subClass({ imageMagick: true }); so the code now looks like this:

我在windows 7上运行nodejs,安装了gm和imagemagick,两个模块之间似乎有冲突,所以我在谷歌上搜索了一下,找到了如何实现这一点。我添加了这一行,这就解决了我的ENOENT问题:var imageMagick = gm.subClass({imageMagick: true});代码是这样的

var gm = require('gm'); 
var imageMagick = gm.subClass({ imageMagick: true });

imageMagick('test/pig.jpg').rotate('green', 45).write('test/crazy_pig.jpg', function (err) {
    if (!err) console.log('crazy pig has arrived');
    else console.log(err);
})

OR you can do that when requiring gm, like so:

或者当需要gm时,你也可以这样做,比如:

var gm = require('gm').subClass({ imageMagick: true });

#3


4  

Had the same problem with Node.js application running on Windows using IIS. Problem has gone when I set "Load User Profile" option in "Advanced settings" of appropriate AppPool to "True"

Node也有同样的问题。使用IIS在Windows上运行的js应用程序。当我在适当的AppPool的“高级设置”中设置“Load User Profile”选项为“True”时,问题就消失了

#4


2  

I faced the same problem and solved it in the given way.

我遇到了同样的问题,并以既定的方式解决了它。

var gm = require('gm'); 

gm('public/uploads/1710410635.jpg').options({imageMagick: true}).resize(240,240).write('public/uploads/1710410635.jpg', function (err) {
if (!err) console.log('Done');
else console.log(err);
})

Note: If you haven't installed imageMagick. Please install that first

注意:如果您没有安装imageMagick。请先安装

#5


1  

Another scenario where this might happen (when using windows) is if you try to run your code from a UNC Path. mapping a drive letter and running over the mapped drive letter solves this problem as well.

另一个可能发生这种情况的场景(当你使用windows时)是如果你试图从UNC路径运行你的代码。映射驱动器号和在映射的驱动器号上运行也解决了这个问题。

#6


1  

I have the same issue as you and this was SOLUTION. ImageMagick was working correctly in terminal/console but not in nodejs (gm module). After 2 days of losing hair i fixed it by adding PATH variable to environment variables process.env.PATH There should be path to your imagemagick and other executables. Node.js has some PATH from system but for some reasone GM is ignoring it and using process.env.PATH

我和你有同样的问题,这就是解决方案。ImageMagick在终端/控制台运行正常,但在nodejs (gm模块)中没有。在丢失头发2天后,我将路径变量添加到环境变量process.env中。路径应该有指向imagemagick和其他可执行文件的路径。节点。js有一些来自系统的路径,但是由于某些原因,GM忽略了它并使用process.env.PATH

I created environment variable PATH(process.env.PATH) and set value to bin:node_modules/.bin:/usr/local/bin:/usr/bin:/bin I'm using MAC OS X

我创建了环境变量PATH(process.env.PATH),并将值设置为bin:node_modules/。bin:/usr/local/bin:/usr/bin:/bin:/bin:我在用MAC OS X

I got imageMagick installed with brew (brew install imagemagick)

我用brew安装了imageMagick (brew install imageMagick)

#7


0  

Because I found this problem many times here on *, I want to share this answer: https://*.com/a/25461564/3970623

因为我在*上多次发现了这个问题,所以我想分享这个答案:https://*.com/a/25461564/3970623

The "spawn ENOENT" seems to be caused by a valid unix tools installation which is accessible using PATH environment variable.

“spawn ENOENT”似乎是由一个有效的unix工具安装引起的,该安装可以使用PATH环境变量进行访问。

#8


0  

In my case it was very simple. It ocurred rigth after instalation of GraphicsMagick in windows 10: I tryed using a console that was yet open before installing GraphicsMagick. Therefore it used old path information and didn´t found GraphicsMagick. Solution: I had to open a new console for running the node for using gm.

就我而言,这很简单。在windows 10中安装了GraphicsMagick之后,它变得更加精确了:我试着在安装GraphicsMagick之前使用一个尚未打开的控制台。因此,使用旧的路径信息,并´t GraphicsMagick找到。解决方案:我必须为使用gm运行节点打开一个新的控制台。

#9


0  

/gm/lib/command.js have an option where you can set the appPath, if gm is already working through the terminal, you can get the path to gm and pass it via the subClass function,In my case gm was installed in /usr/local/bin/ using brew on MacOsx.

通用汽车/ lib /命令。js有一个选项,可以设置appPath,如果gm已经通过终端工作,您可以获取到gm的路径并通过子类函数传递它,在我的例子中,gm是在/usr/local/bin/中安装的,使用的是MacOsx上的brew。

var gm = require('gm').subClass({ appPath: "/usr/local/bin/" });