Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: write EPIPE with node.js and imagemagick

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$ 
like image 363
iank Avatar asked Mar 11 '14 20:03

iank


2 Answers

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.

like image 172
R.A. Lucas Avatar answered Nov 13 '22 06:11

R.A. Lucas


Make sure both imagemagick and graphicsmagick are installed on your machine.

To install graphicsmagick on ubuntu,

$ sudo add-apt-repository ppa:dhor/myway
$ sudo apt-get update
$ sudo apt-get install graphicsmagick
like image 3
Avinash Avatar answered Nov 13 '22 06:11

Avinash