Error: write EPIPE with node.js and imagemagick

iank picture iank · Mar 11, 2014 · Viewed 11k times · Source

I'm lost as to where this error is coming from, and I'm hoping you can help me. I'm new to node and am trying to resize an image with imagemagick:

var express = require('express'), 
fs = require('fs'),
gm = require('gm'),
imagemagick = require('imagemagick'),
var gm = require('gm').subClass({ imageMagick: true });
var app = express();


app.get('/', function (req, res) {
    console.log(__dirname + "/public/photos/4af1e720-a662-11e3-952c-61812ab60f67.jpg");
    imagemagick.resize({
           srcData: fs.readFileSync(__dirname + "/public/photos/4af1e720-a662-11e3-952c-61812ab60f67.jpg", 'binary'),
           width: "400"
    }, function(err,stdout,stderr){
           if (err) console.log(err);
           fs.writeFile(__dirname + "/public/photos/thumbnail/4af1e720-a662-11e3-952c-61812ab60f67.jpg", stdout, 'binary');
    });
});

I get the following:

I've already checked that the folder thumbnail/ exists, and that the image exists. Do you know what else could be going on?

/Users/ik/Dropbox/snapgram/public/photos/4af1e720-a662-11e3-952c-61812ab60f67.jpg

events.js:72
    throw er; // Unhandled 'error' event
          ^
Error: write EPIPE
    at errnoException (net.js:904:11)
    at Object.afterWrite (net.js:720:19)
computername:snapgram ik$ 

Answer

R.A. Lucas picture R.A. Lucas · Jun 15, 2014

I was getting this same error and discovered this issue:

https://github.com/aheckmann/gm/issues/209

You may need both imagemagick and graphicsmagick installed. That solved my issue.