使用GraphicsMagick调整图像大小的Electron App

时间:2017-06-05 15:04:40

标签: image resize imagemagick electron graphicsmagick

我正在尝试使用GraphicsMagick调整我正在构建的Electron应用内的图像大小。

流程(用伪代码描述):

1 - Read EXIF data from image file (async, callback with step 2)
2 - Rename the file (async, callback with step 3)
3 - Create thumbnail (using imagemagick).

步骤1和2正常工作 - 这意味着我可以读取EXIF数据,还可以重命名文件。但是,到第3步的最后一个回调是返回错误。

以下是步骤2和步骤3的代码:

var fs = require('fs')
  , gm = require('gm');

...
...
...
...now inside step 1 callback:

    var randomString = Math.random().toString(36).substr(2, 5);
    console.log(randomString);
    var newFileName = path + '\\' + userName + '_' + randomString + getExtension(file);
    var thumbFileName = path + '\\thumbs\\' + userName + '_' + randomString + '_thumb' + getExtension(file);


    fs.rename(path + '\\' + file, newFileName, function (err) {                             
    if (err) throw err;
        console.log(newFileName);
        gm(newFileName)
        .resizeExact(240, 240)
        .write(thumbFileName, function (err) {
            if (!err) console.log(thumbFileName + 'done');
            else console.log(err);
    });
});

我检查并验证了以下内容:

path + '\\' + file正在重命名为newFileName而没有任何问题。

thumbFileName是正确的,因为path + '\\thumbs\\'存在(我可以在Windows资源管理器中打开路径)。

我为每个文件获取的错误消息是:

C:\Users\AlonAd\Desktop\dev\project\test\testImage [998 years, 6 months, and 12 days]_kwink.JPG
C:\Users\AlonAd\Desktop\dev\project\test\testImage [998 years, 5 months, and 23 days]_z34mj.JPG

Error: Could not execute GraphicsMagick/ImageMagick: gm "convert" "C:\Users\AlonAd\Desktop\dev\project\test\testImage [998 years, 6 months, and 12 days]_kwink.JPG" "-resize" "240x240!" "C:\Users\AlonAd\Desktop\dev\project\test\thumbs\testImage [998 years, 6 months, and 12 days]_kwink_thumb.JPG" this most likely means the gm/convert binaries can't be found
        at ChildProcess.<anonymous> (C:\Users\AlonAd\Desktop\dev\project\renaME\node_modules\gm\lib\command.js:232)
        at emitOne (events.js:96)
        at ChildProcess.emit (events.js:188)
        at ChildProcess.cp.emit (C:\Users\AlonAd\Desktop\dev\project\renaME\node_modules\cross-spawn\lib\enoent.js:36)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:215)
    script.js:68 Error: Could not execute GraphicsMagick/ImageMagick: gm "convert" "C:\Users\AlonAd\Desktop\dev\project\test\testImage [998 years, 5 months, and 23 days]_z34mj.JPG" "-resize" "240x240!" "C:\Users\AlonAd\Desktop\dev\project\test\thumbs\testImage [998 years, 5 months, and 23 days]_z34mj_thumb.JPG" this most likely means the gm/convert binaries can't be found
        at ChildProcess.<anonymous> (C:\Users\AlonAd\Desktop\dev\project\renaME\node_modules\gm\lib\command.js:232)
        at emitOne (events.js:96)
        at ChildProcess.emit (events.js:188)
        at ChildProcess.cp.emit (C:\Users\AlonAd\Desktop\dev\project\renaME\node_modules\cross-spawn\lib\enoent.js:36)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:215)

我已经仔细检查了,控制台中提到的两个图像都在那里,控制台中记录了确切的名称,因此它不是路径或文件名问题,而thumbs目录也在那里。< / p>

我开始怀疑它可能是Electron<->GraphicsMagick问题,或者您可能在这里看到其他问题?

0 个答案:

没有答案